Skip to content

Commit

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

Signed-off-by: Andriy Redko <[email protected]>

* Address code review comments

Signed-off-by: Andriy Redko <[email protected]>

---------

Signed-off-by: Andriy Redko <[email protected]>
(cherry picked from commit 9c81502)
  • Loading branch information
reta committed May 29, 2023
1 parent 3d78190 commit 8539096
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,18 @@ There are multiple low level transports which `OpenSearchClient` could be config
### Create a client using `RestClientTransport`

```java
Transport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
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 @@ -91,7 +102,13 @@ OpenSearchClient client = new OpenSearchClient(transport);
### Create a client using `ApacheHttpClient5Transport`

```java
final Transport transport = ApacheHttpClient5TransportBuilder
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())
.build();
Expand Down

0 comments on commit 8539096

Please sign in to comment.