diff --git a/CHANGELOG.md b/CHANGELOG.md index 5481633389..041f7f11d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Add timeout and throttle to the jenkins workflows ([#231](https://github.com/opensearch-project/opensearch-java/pull/231)) - Updating maintainers, admins and documentation ([#248](https://github.com/opensearch-project/opensearch-java/pull/248)) - Migrate client transports to Apache HttpClient / Core 5.x ([#246](https://github.com/opensearch-project/opensearch-java/pull/246)) +- Document how to use Java 8 Time (JSR 310) objects ([#251](https://github.com/opensearch-project/opensearch-java/pull/251)) - Fixing version and build ([#254](https://github.com/opensearch-project/opensearch-java/pull/254)) ### Deprecated diff --git a/USER_GUIDE.md b/USER_GUIDE.md index f51063052e..6cd7b04b07 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -2,9 +2,10 @@ - [User Guide](#user-guide) - [Sample data](#sample-data) + - [Create a client](#create-a-client) - [Create an index](#create-an-index) - [Index data](#index-data) - - [Search for the document](#search-for-the-document) + - [Search for the document](#search-for-the-documents) - [Search documents using a match query](#search-documents-using-a-match-query) - [Aggregations](#aggregations) - [Delete the document](#delete-the-document) @@ -48,6 +49,21 @@ static class IndexData { } ``` +## Create a client + +```java +Transport transport = new RestClientTransport(restClient, new JacksonJsonpMapper()); +OpenSearchClient client = new OpenSearchClient(transport); +``` + +The `JacksonJsonpMapper` class (2.x versions) only supports Java 7 objects by default. [Java 8 modules](https://github.com/FasterXML/jackson-modules-java8) to support JDK8 classes such as the Date and Time API (JSR-310), `Optional`, and more can be used by including [the additional datatype dependency](https://github.com/FasterXML/jackson-modules-java8#usage) and adding the module. For example, to include JSR-310 classes: + +```java +Transport transport = new RestClientTransport(restClient, + new JacksonJsonpMapper(new ObjectMapper().registerModule(new JavaTimeModule()))); +OpenSearchClient client = new OpenSearchClient(transport); +``` + ## Create an index ```java @@ -119,4 +135,4 @@ client.delete(d -> d.index(index).id("1")); ```java DeleteIndexRequest deleteIndexRequest = new DeleteRequest.Builder().index(index).build(); DeleteIndexResponse deleteIndexResponse = client.indices().delete(deleteIndexRequest); -``` \ No newline at end of file +```