From b61467d96b64064a079b43b8d3417d20471b39e0 Mon Sep 17 00:00:00 2001 From: Vacha Shah Date: Mon, 6 Mar 2023 13:49:13 -0800 Subject: [PATCH] Adding an example to use raw JSON class instead of target classes (#385) Signed-off-by: Vacha Shah --- USER_GUIDE.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 4ab999df6d..58151f805a 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -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) @@ -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 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