Skip to content

Commit

Permalink
Adding an example to use raw JSON class instead of target classes (op…
Browse files Browse the repository at this point in the history
…ensearch-project#385)

Signed-off-by: Vacha Shah <[email protected]>
Signed-off-by: MarinaRazumovsky <[email protected]>
  • Loading branch information
VachaShah authored and MarinaRazumovsky committed Mar 19, 2023
1 parent c721bb9 commit d6109d5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [Create an index](#create-an-index)
- [Index data](#index-data)
- [Search for the documents](#search-for-the-documents)
- [Get raw JSON results](#get-raw-json-results)
- [Search documents using a match query](#search-documents-using-a-match-query)
- [Bulk requests](#bulk-requests)
- [Aggregations](#aggregations)
Expand Down Expand Up @@ -130,6 +131,17 @@ for (int i = 0; i < searchResponse.hits().hits().size(); i++) {
}
```

### Get raw JSON results

When the target class is not defined or if the response result is a semi-structured data not tied to an object definition, use a raw JSON data representation as the target class. For example, the below snippet uses `ObjectNode` from jackson.

```java
SearchResponse<ObjectNode> searchResponse = client.search(b -> b.index(index), ObjectNode.class);
for (int i = 0; i < searchResponse.hits().hits().size(); i++) {
System.out.println(searchResponse.hits().hits().get(i).source());
}
```

## Search documents using a match query

```java
Expand Down

0 comments on commit d6109d5

Please sign in to comment.