Skip to content

Commit

Permalink
Add RestClient initialization code snippets (#501)
Browse files Browse the repository at this point in the history
* Add RestClient initialization code snippets

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

* Address code review comments

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>

---------

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
  • Loading branch information
reta authored May 27, 2023
1 parent 722f257 commit 9c81502
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ There are multiple low level transports which `OpenSearchClient` could be config
### Create a client using `RestClientTransport`

```java
import org.apache.http.HttpHost;

final HttpHost[] hosts = new HttpHost[] {
new HttpHost("localhost", 9200, "http")
};

// Initialize the client with SSL and TLS enabled
final RestClient restClient = RestClient
.builder(hosts)
.build();

OpenSearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
OpenSearchClient client = new OpenSearchClient(transport);
```
Expand All @@ -93,6 +104,12 @@ Upcoming OpenSearch `3.0.0` release brings HTTP/2 support and as such, the `Rest
### Create a client using `ApacheHttpClient5Transport`

```java
import org.apache.hc.core5.http.HttpHost;

final HttpHost[] hosts = new HttpHost[] {
new HttpHost("localhost", "http", 9200)
};

final OpenSearchTransport transport = ApacheHttpClient5TransportBuilder
.builder(hosts)
.setMapper(new JacksonJsonpMapper())
Expand Down

0 comments on commit 9c81502

Please sign in to comment.