Skip to content

Commit

Permalink
Document how to use Java 8 Time (JSR 310) objects
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <widdis@gmail.com>
  • Loading branch information
dbwiddis committed Nov 4, 2022
1 parent 2145e42 commit f68c002
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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))
- Add support for JSR-310 Date and Time API classes ([#251](https://github.com/opensearch-project/opensearch-java/pull/251))
- 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
Expand Down
22 changes: 21 additions & 1 deletion USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -48,6 +49,25 @@ 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
Expand Down

0 comments on commit f68c002

Please sign in to comment.