From e85b1e8ef74c391a8f8632760c668bfb3a50a601 Mon Sep 17 00:00:00 2001 From: Karthik Subramanian Date: Fri, 27 Oct 2023 09:58:35 -0400 Subject: [PATCH 1/9] Adding an example for bulk update operation Signed-off-by: Karthik Subramanian --- .../org/opensearch/client/samples/Bulk.java | 63 +++++++++---------- .../client/samples/IndexingBasics.java | 15 +---- .../client/samples/PointInTime.java | 15 +---- .../org/opensearch/client/samples/Search.java | 7 +-- .../client/samples/util/CommonUtil.java | 45 +++++++++++++ 5 files changed, 81 insertions(+), 64 deletions(-) create mode 100644 samples/src/main/java/org/opensearch/client/samples/util/CommonUtil.java diff --git a/samples/src/main/java/org/opensearch/client/samples/Bulk.java b/samples/src/main/java/org/opensearch/client/samples/Bulk.java index 1613dc9311..4467c07c92 100644 --- a/samples/src/main/java/org/opensearch/client/samples/Bulk.java +++ b/samples/src/main/java/org/opensearch/client/samples/Bulk.java @@ -9,53 +9,37 @@ package org.opensearch.client.samples; import java.util.ArrayList; -import java.util.List; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.opensearch.client.opensearch.OpenSearchClient; import org.opensearch.client.opensearch._types.Refresh; -import org.opensearch.client.opensearch._types.mapping.IntegerNumberProperty; -import org.opensearch.client.opensearch._types.mapping.Property; -import org.opensearch.client.opensearch._types.mapping.TypeMapping; -import org.opensearch.client.opensearch._types.query_dsl.Query; import org.opensearch.client.opensearch.core.BulkRequest; import org.opensearch.client.opensearch.core.BulkResponse; -import org.opensearch.client.opensearch.core.SearchRequest; import org.opensearch.client.opensearch.core.SearchResponse; import org.opensearch.client.opensearch.core.bulk.BulkOperation; import org.opensearch.client.opensearch.core.bulk.IndexOperation; -import org.opensearch.client.opensearch.indices.CreateIndexRequest; import org.opensearch.client.opensearch.indices.DeleteIndexRequest; -import org.opensearch.client.opensearch.indices.IndexSettings; +import org.opensearch.client.samples.util.CommonUtil; import org.opensearch.client.samples.util.IndexData; +import static org.opensearch.client.samples.util.CommonUtil.search; + /** * Run with: ./gradlew :samples:run -Dsamples.mainClass=Bulk */ public class Bulk { private static final Logger LOGGER = LogManager.getLogger(Bulk.class); - + private static OpenSearchClient client; + private static final String indexName = "my-index"; public static void main(String[] args) { try { - var client = SampleClient.create(); + client = SampleClient.create(); var version = client.info().version(); LOGGER.info("Server: {}@{}", version.distribution(), version.number()); - final var indexName = "my-index"; - - if (!client.indices().exists(r -> r.index(indexName)).value()) { - LOGGER.info("Creating index {}", indexName); - IndexSettings settings = new IndexSettings.Builder().numberOfShards("2").numberOfReplicas("1").build(); - TypeMapping mapping = new TypeMapping.Builder().properties( - "age", - new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build() - ).build(); - CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(indexName) - .settings(settings) - .mappings(mapping) - .build(); - client.indices().create(createIndexRequest); - } + CommonUtil.createIndex(client, indexName); LOGGER.info("Bulk indexing documents"); ArrayList ops = new ArrayList<>(); @@ -70,16 +54,29 @@ public static void main(String[] args) { BulkResponse bulkResponse = client.bulk(bulkReq.build()); LOGGER.info("Bulk response items: {}", bulkResponse.items().size()); - Query query = Query.of(qb -> qb.match(mb -> mb.field("title").query(fv -> fv.stringValue("Document")))); - final SearchRequest.Builder searchReq = new SearchRequest.Builder().allowPartialSearchResults(false) - .index(List.of(indexName)) - .size(10) - .source(sc -> sc.fetch(false)) - .ignoreThrottled(false) - .query(query); - SearchResponse searchResponse = client.search(searchReq.build(), IndexData.class); + // wait for the changes to reflect + Thread.sleep(3000); + LOGGER.info("Search & bulk update documents"); + + SearchResponse searchResponse = search(client, indexName, "title", "Document"); LOGGER.info("Found {} documents", searchResponse.hits().hits().size()); + for (var hit : searchResponse.hits().hits()) { + LOGGER.info("Found {} with score {} and id {}", hit.source(), hit.score(), hit.id()); + IndexData finalSearchedData = hit.source(); + finalSearchedData.setText("Updated document"); + BulkRequest request = new BulkRequest.Builder().operations(o -> o.update(u -> u.index(indexName) + .id(hit.id()).document(finalSearchedData))).build(); + bulkResponse = client.bulk(request); + LOGGER.info("Bulk update response items: {}", bulkResponse.items().size()); + } + // wait for the changes to reflect + Thread.sleep(3000); + searchResponse = search(client, indexName, "title", "Document"); + + for (var hit : searchResponse.hits().hits()) { + LOGGER.info("Found {} with score {} and id {}", hit.source(), hit.score(), hit.id()); + } LOGGER.info("Deleting index {}", indexName); DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest.Builder().index(indexName).build(); client.indices().delete(deleteIndexRequest); diff --git a/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java b/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java index db7bfdf3f6..2b63643ff2 100644 --- a/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java +++ b/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java @@ -27,6 +27,7 @@ import org.opensearch.client.opensearch.indices.GetMappingResponse; import org.opensearch.client.opensearch.indices.IndexSettings; import org.opensearch.client.opensearch.indices.PutMappingRequest; +import org.opensearch.client.samples.util.CommonUtil; import org.opensearch.client.samples.util.IndexData; /** @@ -44,19 +45,7 @@ public static void main(String[] args) { final var indexName = "my-index"; - if (!client.indices().exists(r -> r.index(indexName)).value()) { - LOGGER.info("Creating index {}", indexName); - IndexSettings settings = new IndexSettings.Builder().numberOfShards("2").numberOfReplicas("1").build(); - TypeMapping mapping = new TypeMapping.Builder().properties( - "age", - new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build() - ).build(); - CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(indexName) - .settings(settings) - .mappings(mapping) - .build(); - client.indices().create(createIndexRequest); - } + CommonUtil.createIndex(client, indexName); LOGGER.info("Indexing documents"); IndexData indexData = new IndexData("Document 1", "Text for document 1"); diff --git a/samples/src/main/java/org/opensearch/client/samples/PointInTime.java b/samples/src/main/java/org/opensearch/client/samples/PointInTime.java index 53e29743c4..bdbd54abcf 100644 --- a/samples/src/main/java/org/opensearch/client/samples/PointInTime.java +++ b/samples/src/main/java/org/opensearch/client/samples/PointInTime.java @@ -23,6 +23,7 @@ import org.opensearch.client.opensearch.indices.CreateIndexRequest; import org.opensearch.client.opensearch.indices.DeleteIndexRequest; import org.opensearch.client.opensearch.indices.IndexSettings; +import org.opensearch.client.samples.util.CommonUtil; /** * Run with: ./gradlew :samples:run -Dsamples.mainClass=PointInTime @@ -39,19 +40,7 @@ public static void main(String[] args) { final var indexName = "my-index"; - if (!client.indices().exists(r -> r.index(indexName)).value()) { - LOGGER.info("Creating index {}", indexName); - IndexSettings settings = new IndexSettings.Builder().numberOfShards("2").numberOfReplicas("1").build(); - TypeMapping mapping = new TypeMapping.Builder().properties( - "age", - new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build() - ).build(); - CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(indexName) - .settings(settings) - .mappings(mapping) - .build(); - client.indices().create(createIndexRequest); - } + CommonUtil.createIndex(client, indexName); CreatePitRequest createPitRequest = new CreatePitRequest.Builder().targetIndexes(Collections.singletonList(indexName)) .keepAlive(new Time.Builder().time("100m").build()) diff --git a/samples/src/main/java/org/opensearch/client/samples/Search.java b/samples/src/main/java/org/opensearch/client/samples/Search.java index ce357d2942..a2bbf9bbd3 100644 --- a/samples/src/main/java/org/opensearch/client/samples/Search.java +++ b/samples/src/main/java/org/opensearch/client/samples/Search.java @@ -40,6 +40,7 @@ import org.opensearch.client.opensearch.indices.IndexSettings; import org.opensearch.client.opensearch.indices.IndexSettingsAnalysis; import org.opensearch.client.samples.util.AppData; +import org.opensearch.client.samples.util.CommonUtil; import org.opensearch.client.samples.util.IndexData; /** @@ -59,11 +60,7 @@ public static void main(String[] args) { final var indexName = "my-index"; - if (!client.indices().exists(r -> r.index(indexName)).value()) { - LOGGER.info("Creating index {}", indexName); - CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(indexName).build(); - client.indices().create(createIndexRequest); - } + CommonUtil.createIndex(client, indexName); LOGGER.info("Indexing documents"); IndexData indexData = new IndexData("Document 1", "Text for document 1"); diff --git a/samples/src/main/java/org/opensearch/client/samples/util/CommonUtil.java b/samples/src/main/java/org/opensearch/client/samples/util/CommonUtil.java new file mode 100644 index 0000000000..70551ecad5 --- /dev/null +++ b/samples/src/main/java/org/opensearch/client/samples/util/CommonUtil.java @@ -0,0 +1,45 @@ +package org.opensearch.client.samples.util; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.opensearch.client.opensearch.OpenSearchClient; +import org.opensearch.client.opensearch._types.mapping.IntegerNumberProperty; +import org.opensearch.client.opensearch._types.mapping.Property; +import org.opensearch.client.opensearch._types.mapping.TypeMapping; +import org.opensearch.client.opensearch._types.query_dsl.Query; +import org.opensearch.client.opensearch.core.SearchRequest; +import org.opensearch.client.opensearch.core.SearchResponse; +import org.opensearch.client.opensearch.indices.CreateIndexRequest; +import org.opensearch.client.opensearch.indices.IndexSettings; + +import java.io.IOException; +import java.util.List; + + +public class CommonUtil { + private static final Logger LOGGER = LogManager.getLogger(CommonUtil.class); + public static void createIndex(OpenSearchClient client, String indexName) throws IOException { + if (!client.indices().exists(r -> r.index(indexName)).value()) { + LOGGER.info("Creating index {}", indexName); + IndexSettings settings = new IndexSettings.Builder().numberOfShards("2").numberOfReplicas("1").build(); + TypeMapping mapping = new TypeMapping.Builder().properties( + "age", + new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build() + ).build(); + CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(indexName) + .settings(settings) + .mappings(mapping) + .build(); + client.indices().create(createIndexRequest); + } + } + public static SearchResponse search(OpenSearchClient client, String indexName, String field, String value) throws IOException { + Query query = Query.of(qb -> qb.match(mb -> mb.field(field).query(fv -> fv.stringValue(value)))); + final SearchRequest.Builder searchReq = new SearchRequest.Builder().allowPartialSearchResults(false) + .index(List.of(indexName)) + .size(10) + .ignoreThrottled(false) + .query(query); + return client.search(searchReq.build(), IndexData.class); + } +} From fb8aefad60d5e72cff414649093e146de796bf10 Mon Sep 17 00:00:00 2001 From: Karthik Subramanian Date: Fri, 27 Oct 2023 10:40:36 -0400 Subject: [PATCH 2/9] updated the changelog.md Signed-off-by: Karthik Subramanian --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84398bbad5..2302733136 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,7 +35,8 @@ This section is for maintaining a changelog for all breaking changes for the cli ### Dependencies ### Changed -Allow null values in arrays ([#687](https://github.com/opensearch-project/opensearch-java/pull/687)) +- Allow null values in arrays ([#687](https://github.com/opensearch-project/opensearch-java/pull/687)) +- Add an example for bulk update operation in samples ([#690](https://github.com/opensearch-project/opensearch-java/pull/690)) ### Deprecated From ea6ff7e8a024263f7cad98a0a9df56adf4b20c60 Mon Sep 17 00:00:00 2001 From: Karthik Subramanian Date: Fri, 27 Oct 2023 10:44:01 -0400 Subject: [PATCH 3/9] changes made by spotlessApply Signed-off-by: Karthik Subramanian --- .../org/opensearch/client/samples/Bulk.java | 11 +++---- .../client/samples/IndexingBasics.java | 5 ---- .../client/samples/PointInTime.java | 5 ---- .../org/opensearch/client/samples/Search.java | 1 - .../client/samples/util/CommonUtil.java | 29 ++++++++++--------- 5 files changed, 21 insertions(+), 30 deletions(-) diff --git a/samples/src/main/java/org/opensearch/client/samples/Bulk.java b/samples/src/main/java/org/opensearch/client/samples/Bulk.java index 4467c07c92..ee5e2bb5fa 100644 --- a/samples/src/main/java/org/opensearch/client/samples/Bulk.java +++ b/samples/src/main/java/org/opensearch/client/samples/Bulk.java @@ -8,8 +8,9 @@ package org.opensearch.client.samples; -import java.util.ArrayList; +import static org.opensearch.client.samples.util.CommonUtil.search; +import java.util.ArrayList; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.client.opensearch.OpenSearchClient; @@ -23,8 +24,6 @@ import org.opensearch.client.samples.util.CommonUtil; import org.opensearch.client.samples.util.IndexData; -import static org.opensearch.client.samples.util.CommonUtil.search; - /** * Run with: ./gradlew :samples:run -Dsamples.mainClass=Bulk */ @@ -32,6 +31,7 @@ public class Bulk { private static final Logger LOGGER = LogManager.getLogger(Bulk.class); private static OpenSearchClient client; private static final String indexName = "my-index"; + public static void main(String[] args) { try { client = SampleClient.create(); @@ -65,8 +65,9 @@ public static void main(String[] args) { LOGGER.info("Found {} with score {} and id {}", hit.source(), hit.score(), hit.id()); IndexData finalSearchedData = hit.source(); finalSearchedData.setText("Updated document"); - BulkRequest request = new BulkRequest.Builder().operations(o -> o.update(u -> u.index(indexName) - .id(hit.id()).document(finalSearchedData))).build(); + BulkRequest request = new BulkRequest.Builder().operations( + o -> o.update(u -> u.index(indexName).id(hit.id()).document(finalSearchedData)) + ).build(); bulkResponse = client.bulk(request); LOGGER.info("Bulk update response items: {}", bulkResponse.items().size()); } diff --git a/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java b/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java index 2b63643ff2..aa5b28c624 100644 --- a/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java +++ b/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java @@ -14,18 +14,13 @@ import org.opensearch.client.json.JsonData; import org.opensearch.client.opensearch._types.mapping.DynamicMapping; import org.opensearch.client.opensearch._types.mapping.FieldNamesField; -import org.opensearch.client.opensearch._types.mapping.IntegerNumberProperty; -import org.opensearch.client.opensearch._types.mapping.Property; import org.opensearch.client.opensearch._types.mapping.RoutingField; import org.opensearch.client.opensearch._types.mapping.SourceField; -import org.opensearch.client.opensearch._types.mapping.TypeMapping; import org.opensearch.client.opensearch.core.IndexRequest; import org.opensearch.client.opensearch.core.SearchResponse; -import org.opensearch.client.opensearch.indices.CreateIndexRequest; import org.opensearch.client.opensearch.indices.DeleteIndexRequest; import org.opensearch.client.opensearch.indices.GetMappingRequest; import org.opensearch.client.opensearch.indices.GetMappingResponse; -import org.opensearch.client.opensearch.indices.IndexSettings; import org.opensearch.client.opensearch.indices.PutMappingRequest; import org.opensearch.client.samples.util.CommonUtil; import org.opensearch.client.samples.util.IndexData; diff --git a/samples/src/main/java/org/opensearch/client/samples/PointInTime.java b/samples/src/main/java/org/opensearch/client/samples/PointInTime.java index bdbd54abcf..1e8773aba2 100644 --- a/samples/src/main/java/org/opensearch/client/samples/PointInTime.java +++ b/samples/src/main/java/org/opensearch/client/samples/PointInTime.java @@ -12,17 +12,12 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.client.opensearch._types.Time; -import org.opensearch.client.opensearch._types.mapping.IntegerNumberProperty; -import org.opensearch.client.opensearch._types.mapping.Property; -import org.opensearch.client.opensearch._types.mapping.TypeMapping; import org.opensearch.client.opensearch.core.pit.CreatePitRequest; import org.opensearch.client.opensearch.core.pit.CreatePitResponse; import org.opensearch.client.opensearch.core.pit.DeletePitRequest; import org.opensearch.client.opensearch.core.pit.DeletePitResponse; import org.opensearch.client.opensearch.core.pit.ListAllPitResponse; -import org.opensearch.client.opensearch.indices.CreateIndexRequest; import org.opensearch.client.opensearch.indices.DeleteIndexRequest; -import org.opensearch.client.opensearch.indices.IndexSettings; import org.opensearch.client.samples.util.CommonUtil; /** diff --git a/samples/src/main/java/org/opensearch/client/samples/Search.java b/samples/src/main/java/org/opensearch/client/samples/Search.java index a2bbf9bbd3..31927b883a 100644 --- a/samples/src/main/java/org/opensearch/client/samples/Search.java +++ b/samples/src/main/java/org/opensearch/client/samples/Search.java @@ -35,7 +35,6 @@ import org.opensearch.client.opensearch.core.search.PhraseSuggester; import org.opensearch.client.opensearch.core.search.Suggester; import org.opensearch.client.opensearch.core.search.TermSuggester; -import org.opensearch.client.opensearch.indices.CreateIndexRequest; import org.opensearch.client.opensearch.indices.DeleteIndexRequest; import org.opensearch.client.opensearch.indices.IndexSettings; import org.opensearch.client.opensearch.indices.IndexSettingsAnalysis; diff --git a/samples/src/main/java/org/opensearch/client/samples/util/CommonUtil.java b/samples/src/main/java/org/opensearch/client/samples/util/CommonUtil.java index 70551ecad5..1914bbd2d1 100644 --- a/samples/src/main/java/org/opensearch/client/samples/util/CommonUtil.java +++ b/samples/src/main/java/org/opensearch/client/samples/util/CommonUtil.java @@ -1,5 +1,7 @@ package org.opensearch.client.samples.util; +import java.io.IOException; +import java.util.List; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.client.opensearch.OpenSearchClient; @@ -12,34 +14,33 @@ import org.opensearch.client.opensearch.indices.CreateIndexRequest; import org.opensearch.client.opensearch.indices.IndexSettings; -import java.io.IOException; -import java.util.List; - - public class CommonUtil { private static final Logger LOGGER = LogManager.getLogger(CommonUtil.class); + public static void createIndex(OpenSearchClient client, String indexName) throws IOException { if (!client.indices().exists(r -> r.index(indexName)).value()) { LOGGER.info("Creating index {}", indexName); IndexSettings settings = new IndexSettings.Builder().numberOfShards("2").numberOfReplicas("1").build(); TypeMapping mapping = new TypeMapping.Builder().properties( - "age", - new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build() + "age", + new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build() ).build(); CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(indexName) - .settings(settings) - .mappings(mapping) - .build(); + .settings(settings) + .mappings(mapping) + .build(); client.indices().create(createIndexRequest); } } - public static SearchResponse search(OpenSearchClient client, String indexName, String field, String value) throws IOException { + + public static SearchResponse search(OpenSearchClient client, String indexName, String field, String value) + throws IOException { Query query = Query.of(qb -> qb.match(mb -> mb.field(field).query(fv -> fv.stringValue(value)))); final SearchRequest.Builder searchReq = new SearchRequest.Builder().allowPartialSearchResults(false) - .index(List.of(indexName)) - .size(10) - .ignoreThrottled(false) - .query(query); + .index(List.of(indexName)) + .size(10) + .ignoreThrottled(false) + .query(query); return client.search(searchReq.build(), IndexData.class); } } From 448ef4db775bf6f9d342ceac782716c3a2ffdce1 Mon Sep 17 00:00:00 2001 From: Karthik Subramanian Date: Fri, 27 Oct 2023 11:33:26 -0400 Subject: [PATCH 4/9] removing CommonUtil based on review comments Signed-off-by: Karthik Subramanian --- .../org/opensearch/client/samples/Bulk.java | 38 +++++++++++++-- .../client/samples/IndexingBasics.java | 20 +++++++- .../client/samples/PointInTime.java | 20 +++++++- .../org/opensearch/client/samples/Search.java | 17 ++++++- .../client/samples/util/CommonUtil.java | 46 ------------------- 5 files changed, 85 insertions(+), 56 deletions(-) delete mode 100644 samples/src/main/java/org/opensearch/client/samples/util/CommonUtil.java diff --git a/samples/src/main/java/org/opensearch/client/samples/Bulk.java b/samples/src/main/java/org/opensearch/client/samples/Bulk.java index ee5e2bb5fa..ada760d137 100644 --- a/samples/src/main/java/org/opensearch/client/samples/Bulk.java +++ b/samples/src/main/java/org/opensearch/client/samples/Bulk.java @@ -8,20 +8,27 @@ package org.opensearch.client.samples; -import static org.opensearch.client.samples.util.CommonUtil.search; - +import java.io.IOException; import java.util.ArrayList; +import java.util.List; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.client.opensearch.OpenSearchClient; import org.opensearch.client.opensearch._types.Refresh; +import org.opensearch.client.opensearch._types.mapping.IntegerNumberProperty; +import org.opensearch.client.opensearch._types.mapping.Property; +import org.opensearch.client.opensearch._types.mapping.TypeMapping; +import org.opensearch.client.opensearch._types.query_dsl.Query; import org.opensearch.client.opensearch.core.BulkRequest; import org.opensearch.client.opensearch.core.BulkResponse; +import org.opensearch.client.opensearch.core.SearchRequest; import org.opensearch.client.opensearch.core.SearchResponse; import org.opensearch.client.opensearch.core.bulk.BulkOperation; import org.opensearch.client.opensearch.core.bulk.IndexOperation; +import org.opensearch.client.opensearch.indices.CreateIndexRequest; import org.opensearch.client.opensearch.indices.DeleteIndexRequest; -import org.opensearch.client.samples.util.CommonUtil; +import org.opensearch.client.opensearch.indices.IndexSettings; import org.opensearch.client.samples.util.IndexData; /** @@ -39,7 +46,19 @@ public static void main(String[] args) { var version = client.info().version(); LOGGER.info("Server: {}@{}", version.distribution(), version.number()); - CommonUtil.createIndex(client, indexName); + if (!client.indices().exists(r -> r.index(indexName)).value()) { + LOGGER.info("Creating index {}", indexName); + IndexSettings settings = new IndexSettings.Builder().numberOfShards("2").numberOfReplicas("1").build(); + TypeMapping mapping = new TypeMapping.Builder().properties( + "age", + new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build() + ).build(); + CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(indexName) + .settings(settings) + .mappings(mapping) + .build(); + client.indices().create(createIndexRequest); + } LOGGER.info("Bulk indexing documents"); ArrayList ops = new ArrayList<>(); @@ -85,4 +104,15 @@ public static void main(String[] args) { LOGGER.error("Unexpected exception", e); } } + + public static SearchResponse search(OpenSearchClient client, String indexName, String field, String value) + throws IOException { + Query query = Query.of(qb -> qb.match(mb -> mb.field(field).query(fv -> fv.stringValue(value)))); + final SearchRequest.Builder searchReq = new SearchRequest.Builder().allowPartialSearchResults(false) + .index(List.of(indexName)) + .size(10) + .ignoreThrottled(false) + .query(query); + return client.search(searchReq.build(), IndexData.class); + } } diff --git a/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java b/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java index aa5b28c624..74eb63b2b7 100644 --- a/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java +++ b/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java @@ -14,15 +14,19 @@ import org.opensearch.client.json.JsonData; import org.opensearch.client.opensearch._types.mapping.DynamicMapping; import org.opensearch.client.opensearch._types.mapping.FieldNamesField; +import org.opensearch.client.opensearch._types.mapping.IntegerNumberProperty; +import org.opensearch.client.opensearch._types.mapping.Property; import org.opensearch.client.opensearch._types.mapping.RoutingField; import org.opensearch.client.opensearch._types.mapping.SourceField; +import org.opensearch.client.opensearch._types.mapping.TypeMapping; import org.opensearch.client.opensearch.core.IndexRequest; import org.opensearch.client.opensearch.core.SearchResponse; +import org.opensearch.client.opensearch.indices.CreateIndexRequest; import org.opensearch.client.opensearch.indices.DeleteIndexRequest; import org.opensearch.client.opensearch.indices.GetMappingRequest; import org.opensearch.client.opensearch.indices.GetMappingResponse; +import org.opensearch.client.opensearch.indices.IndexSettings; import org.opensearch.client.opensearch.indices.PutMappingRequest; -import org.opensearch.client.samples.util.CommonUtil; import org.opensearch.client.samples.util.IndexData; /** @@ -40,7 +44,19 @@ public static void main(String[] args) { final var indexName = "my-index"; - CommonUtil.createIndex(client, indexName); + if (!client.indices().exists(r -> r.index(indexName)).value()) { + LOGGER.info("Creating index {}", indexName); + IndexSettings settings = new IndexSettings.Builder().numberOfShards("2").numberOfReplicas("1").build(); + TypeMapping mapping = new TypeMapping.Builder().properties( + "age", + new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build() + ).build(); + CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(indexName) + .settings(settings) + .mappings(mapping) + .build(); + client.indices().create(createIndexRequest); + } LOGGER.info("Indexing documents"); IndexData indexData = new IndexData("Document 1", "Text for document 1"); diff --git a/samples/src/main/java/org/opensearch/client/samples/PointInTime.java b/samples/src/main/java/org/opensearch/client/samples/PointInTime.java index 1e8773aba2..14ed4bfb5c 100644 --- a/samples/src/main/java/org/opensearch/client/samples/PointInTime.java +++ b/samples/src/main/java/org/opensearch/client/samples/PointInTime.java @@ -12,13 +12,17 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.client.opensearch._types.Time; +import org.opensearch.client.opensearch._types.mapping.IntegerNumberProperty; +import org.opensearch.client.opensearch._types.mapping.Property; +import org.opensearch.client.opensearch._types.mapping.TypeMapping; import org.opensearch.client.opensearch.core.pit.CreatePitRequest; import org.opensearch.client.opensearch.core.pit.CreatePitResponse; import org.opensearch.client.opensearch.core.pit.DeletePitRequest; import org.opensearch.client.opensearch.core.pit.DeletePitResponse; import org.opensearch.client.opensearch.core.pit.ListAllPitResponse; +import org.opensearch.client.opensearch.indices.CreateIndexRequest; import org.opensearch.client.opensearch.indices.DeleteIndexRequest; -import org.opensearch.client.samples.util.CommonUtil; +import org.opensearch.client.opensearch.indices.IndexSettings; /** * Run with: ./gradlew :samples:run -Dsamples.mainClass=PointInTime @@ -35,7 +39,19 @@ public static void main(String[] args) { final var indexName = "my-index"; - CommonUtil.createIndex(client, indexName); + if (!client.indices().exists(r -> r.index(indexName)).value()) { + LOGGER.info("Creating index {}", indexName); + IndexSettings settings = new IndexSettings.Builder().numberOfShards("2").numberOfReplicas("1").build(); + TypeMapping mapping = new TypeMapping.Builder().properties( + "age", + new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build() + ).build(); + CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(indexName) + .settings(settings) + .mappings(mapping) + .build(); + client.indices().create(createIndexRequest); + } CreatePitRequest createPitRequest = new CreatePitRequest.Builder().targetIndexes(Collections.singletonList(indexName)) .keepAlive(new Time.Builder().time("100m").build()) diff --git a/samples/src/main/java/org/opensearch/client/samples/Search.java b/samples/src/main/java/org/opensearch/client/samples/Search.java index 31927b883a..31bc62501f 100644 --- a/samples/src/main/java/org/opensearch/client/samples/Search.java +++ b/samples/src/main/java/org/opensearch/client/samples/Search.java @@ -23,6 +23,7 @@ import org.opensearch.client.opensearch._types.analysis.ShingleTokenFilter; import org.opensearch.client.opensearch._types.analysis.TokenFilter; import org.opensearch.client.opensearch._types.analysis.TokenFilterDefinition; +import org.opensearch.client.opensearch._types.mapping.IntegerNumberProperty; import org.opensearch.client.opensearch._types.mapping.Property; import org.opensearch.client.opensearch._types.mapping.TextProperty; import org.opensearch.client.opensearch._types.mapping.TypeMapping; @@ -35,11 +36,11 @@ import org.opensearch.client.opensearch.core.search.PhraseSuggester; import org.opensearch.client.opensearch.core.search.Suggester; import org.opensearch.client.opensearch.core.search.TermSuggester; +import org.opensearch.client.opensearch.indices.CreateIndexRequest; import org.opensearch.client.opensearch.indices.DeleteIndexRequest; import org.opensearch.client.opensearch.indices.IndexSettings; import org.opensearch.client.opensearch.indices.IndexSettingsAnalysis; import org.opensearch.client.samples.util.AppData; -import org.opensearch.client.samples.util.CommonUtil; import org.opensearch.client.samples.util.IndexData; /** @@ -59,7 +60,19 @@ public static void main(String[] args) { final var indexName = "my-index"; - CommonUtil.createIndex(client, indexName); + if (!client.indices().exists(r -> r.index(indexName)).value()) { + LOGGER.info("Creating index {}", indexName); + IndexSettings settings = new IndexSettings.Builder().numberOfShards("2").numberOfReplicas("1").build(); + TypeMapping mapping = new TypeMapping.Builder().properties( + "age", + new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build() + ).build(); + CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(indexName) + .settings(settings) + .mappings(mapping) + .build(); + client.indices().create(createIndexRequest); + } LOGGER.info("Indexing documents"); IndexData indexData = new IndexData("Document 1", "Text for document 1"); diff --git a/samples/src/main/java/org/opensearch/client/samples/util/CommonUtil.java b/samples/src/main/java/org/opensearch/client/samples/util/CommonUtil.java deleted file mode 100644 index 1914bbd2d1..0000000000 --- a/samples/src/main/java/org/opensearch/client/samples/util/CommonUtil.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.opensearch.client.samples.util; - -import java.io.IOException; -import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.opensearch.client.opensearch.OpenSearchClient; -import org.opensearch.client.opensearch._types.mapping.IntegerNumberProperty; -import org.opensearch.client.opensearch._types.mapping.Property; -import org.opensearch.client.opensearch._types.mapping.TypeMapping; -import org.opensearch.client.opensearch._types.query_dsl.Query; -import org.opensearch.client.opensearch.core.SearchRequest; -import org.opensearch.client.opensearch.core.SearchResponse; -import org.opensearch.client.opensearch.indices.CreateIndexRequest; -import org.opensearch.client.opensearch.indices.IndexSettings; - -public class CommonUtil { - private static final Logger LOGGER = LogManager.getLogger(CommonUtil.class); - - public static void createIndex(OpenSearchClient client, String indexName) throws IOException { - if (!client.indices().exists(r -> r.index(indexName)).value()) { - LOGGER.info("Creating index {}", indexName); - IndexSettings settings = new IndexSettings.Builder().numberOfShards("2").numberOfReplicas("1").build(); - TypeMapping mapping = new TypeMapping.Builder().properties( - "age", - new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build() - ).build(); - CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(indexName) - .settings(settings) - .mappings(mapping) - .build(); - client.indices().create(createIndexRequest); - } - } - - public static SearchResponse search(OpenSearchClient client, String indexName, String field, String value) - throws IOException { - Query query = Query.of(qb -> qb.match(mb -> mb.field(field).query(fv -> fv.stringValue(value)))); - final SearchRequest.Builder searchReq = new SearchRequest.Builder().allowPartialSearchResults(false) - .index(List.of(indexName)) - .size(10) - .ignoreThrottled(false) - .query(query); - return client.search(searchReq.build(), IndexData.class); - } -} From dad800899cf4708a966114cc8baa189d44a91e29 Mon Sep 17 00:00:00 2001 From: Karthik Subramanian Date: Fri, 27 Oct 2023 11:38:00 -0400 Subject: [PATCH 5/9] reverting files to original state Signed-off-by: Karthik Subramanian --- .../org/opensearch/client/samples/IndexingBasics.java | 10 +++++----- .../org/opensearch/client/samples/PointInTime.java | 10 +++++----- .../java/org/opensearch/client/samples/Search.java | 11 +---------- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java b/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java index 74eb63b2b7..db7bfdf3f6 100644 --- a/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java +++ b/samples/src/main/java/org/opensearch/client/samples/IndexingBasics.java @@ -48,13 +48,13 @@ public static void main(String[] args) { LOGGER.info("Creating index {}", indexName); IndexSettings settings = new IndexSettings.Builder().numberOfShards("2").numberOfReplicas("1").build(); TypeMapping mapping = new TypeMapping.Builder().properties( - "age", - new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build() + "age", + new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build() ).build(); CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(indexName) - .settings(settings) - .mappings(mapping) - .build(); + .settings(settings) + .mappings(mapping) + .build(); client.indices().create(createIndexRequest); } diff --git a/samples/src/main/java/org/opensearch/client/samples/PointInTime.java b/samples/src/main/java/org/opensearch/client/samples/PointInTime.java index 14ed4bfb5c..53e29743c4 100644 --- a/samples/src/main/java/org/opensearch/client/samples/PointInTime.java +++ b/samples/src/main/java/org/opensearch/client/samples/PointInTime.java @@ -43,13 +43,13 @@ public static void main(String[] args) { LOGGER.info("Creating index {}", indexName); IndexSettings settings = new IndexSettings.Builder().numberOfShards("2").numberOfReplicas("1").build(); TypeMapping mapping = new TypeMapping.Builder().properties( - "age", - new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build() + "age", + new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build() ).build(); CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(indexName) - .settings(settings) - .mappings(mapping) - .build(); + .settings(settings) + .mappings(mapping) + .build(); client.indices().create(createIndexRequest); } diff --git a/samples/src/main/java/org/opensearch/client/samples/Search.java b/samples/src/main/java/org/opensearch/client/samples/Search.java index 31bc62501f..ce357d2942 100644 --- a/samples/src/main/java/org/opensearch/client/samples/Search.java +++ b/samples/src/main/java/org/opensearch/client/samples/Search.java @@ -23,7 +23,6 @@ import org.opensearch.client.opensearch._types.analysis.ShingleTokenFilter; import org.opensearch.client.opensearch._types.analysis.TokenFilter; import org.opensearch.client.opensearch._types.analysis.TokenFilterDefinition; -import org.opensearch.client.opensearch._types.mapping.IntegerNumberProperty; import org.opensearch.client.opensearch._types.mapping.Property; import org.opensearch.client.opensearch._types.mapping.TextProperty; import org.opensearch.client.opensearch._types.mapping.TypeMapping; @@ -62,15 +61,7 @@ public static void main(String[] args) { if (!client.indices().exists(r -> r.index(indexName)).value()) { LOGGER.info("Creating index {}", indexName); - IndexSettings settings = new IndexSettings.Builder().numberOfShards("2").numberOfReplicas("1").build(); - TypeMapping mapping = new TypeMapping.Builder().properties( - "age", - new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build() - ).build(); - CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(indexName) - .settings(settings) - .mappings(mapping) - .build(); + CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(indexName).build(); client.indices().create(createIndexRequest); } From b8dec677d5c807ee45bbf1f2d63877a1a743fa4b Mon Sep 17 00:00:00 2001 From: Karthik Subramanian Date: Fri, 27 Oct 2023 11:45:25 -0400 Subject: [PATCH 6/9] changes by spotlessApply Signed-off-by: Karthik Subramanian --- .../org/opensearch/client/samples/Bulk.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/samples/src/main/java/org/opensearch/client/samples/Bulk.java b/samples/src/main/java/org/opensearch/client/samples/Bulk.java index ada760d137..8d367b15f5 100644 --- a/samples/src/main/java/org/opensearch/client/samples/Bulk.java +++ b/samples/src/main/java/org/opensearch/client/samples/Bulk.java @@ -11,7 +11,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.client.opensearch.OpenSearchClient; @@ -50,13 +49,13 @@ public static void main(String[] args) { LOGGER.info("Creating index {}", indexName); IndexSettings settings = new IndexSettings.Builder().numberOfShards("2").numberOfReplicas("1").build(); TypeMapping mapping = new TypeMapping.Builder().properties( - "age", - new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build() + "age", + new Property.Builder().integer(new IntegerNumberProperty.Builder().build()).build() ).build(); CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder().index(indexName) - .settings(settings) - .mappings(mapping) - .build(); + .settings(settings) + .mappings(mapping) + .build(); client.indices().create(createIndexRequest); } @@ -106,13 +105,13 @@ public static void main(String[] args) { } public static SearchResponse search(OpenSearchClient client, String indexName, String field, String value) - throws IOException { + throws IOException { Query query = Query.of(qb -> qb.match(mb -> mb.field(field).query(fv -> fv.stringValue(value)))); final SearchRequest.Builder searchReq = new SearchRequest.Builder().allowPartialSearchResults(false) - .index(List.of(indexName)) - .size(10) - .ignoreThrottled(false) - .query(query); + .index(List.of(indexName)) + .size(10) + .ignoreThrottled(false) + .query(query); return client.search(searchReq.build(), IndexData.class); } } From edefa90d7a11d016081f223cec6f4e6ffe488459 Mon Sep 17 00:00:00 2001 From: Karthik Subramanian Date: Fri, 27 Oct 2023 11:55:22 -0400 Subject: [PATCH 7/9] removing static fields and unnecessary waits Signed-off-by: Karthik Subramanian --- .../java/org/opensearch/client/samples/Bulk.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/samples/src/main/java/org/opensearch/client/samples/Bulk.java b/samples/src/main/java/org/opensearch/client/samples/Bulk.java index 8d367b15f5..628133f255 100644 --- a/samples/src/main/java/org/opensearch/client/samples/Bulk.java +++ b/samples/src/main/java/org/opensearch/client/samples/Bulk.java @@ -35,16 +35,16 @@ */ public class Bulk { private static final Logger LOGGER = LogManager.getLogger(Bulk.class); - private static OpenSearchClient client; - private static final String indexName = "my-index"; public static void main(String[] args) { try { - client = SampleClient.create(); + var client = SampleClient.create(); var version = client.info().version(); LOGGER.info("Server: {}@{}", version.distribution(), version.number()); + final var indexName = "my-index"; + if (!client.indices().exists(r -> r.index(indexName)).value()) { LOGGER.info("Creating index {}", indexName); IndexSettings settings = new IndexSettings.Builder().numberOfShards("2").numberOfReplicas("1").build(); @@ -72,8 +72,6 @@ public static void main(String[] args) { BulkResponse bulkResponse = client.bulk(bulkReq.build()); LOGGER.info("Bulk response items: {}", bulkResponse.items().size()); - // wait for the changes to reflect - Thread.sleep(3000); LOGGER.info("Search & bulk update documents"); SearchResponse searchResponse = search(client, indexName, "title", "Document"); @@ -85,12 +83,10 @@ public static void main(String[] args) { finalSearchedData.setText("Updated document"); BulkRequest request = new BulkRequest.Builder().operations( o -> o.update(u -> u.index(indexName).id(hit.id()).document(finalSearchedData)) - ).build(); + ).refresh(Refresh.WaitFor).build(); bulkResponse = client.bulk(request); LOGGER.info("Bulk update response items: {}", bulkResponse.items().size()); } - // wait for the changes to reflect - Thread.sleep(3000); searchResponse = search(client, indexName, "title", "Document"); for (var hit : searchResponse.hits().hits()) { From 2a1fc2e6909f5bbde2842e351f7188019b160928 Mon Sep 17 00:00:00 2001 From: Karthik Subramanian Date: Fri, 27 Oct 2023 14:51:32 -0400 Subject: [PATCH 8/9] changes as per review comments Signed-off-by: Karthik Subramanian --- .../org/opensearch/client/samples/Bulk.java | 41 +++++++------------ 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/samples/src/main/java/org/opensearch/client/samples/Bulk.java b/samples/src/main/java/org/opensearch/client/samples/Bulk.java index 628133f255..0407f8bc98 100644 --- a/samples/src/main/java/org/opensearch/client/samples/Bulk.java +++ b/samples/src/main/java/org/opensearch/client/samples/Bulk.java @@ -8,12 +8,10 @@ package org.opensearch.client.samples; -import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.client.opensearch.OpenSearchClient; import org.opensearch.client.opensearch._types.Refresh; import org.opensearch.client.opensearch._types.mapping.IntegerNumberProperty; import org.opensearch.client.opensearch._types.mapping.Property; @@ -72,26 +70,28 @@ public static void main(String[] args) { BulkResponse bulkResponse = client.bulk(bulkReq.build()); LOGGER.info("Bulk response items: {}", bulkResponse.items().size()); - LOGGER.info("Search & bulk update documents"); + Query query = Query.of(qb -> qb.match(mb -> mb.field("title").query(fv -> fv.stringValue("document")))); + final SearchRequest.Builder searchReq = new SearchRequest.Builder().allowPartialSearchResults(false) + .index(List.of(indexName)) + .size(10) + .ignoreThrottled(false) + .query(query); - SearchResponse searchResponse = search(client, indexName, "title", "Document"); + SearchResponse searchResponse = client.search(searchReq.build(), IndexData.class); LOGGER.info("Found {} documents", searchResponse.hits().hits().size()); for (var hit : searchResponse.hits().hits()) { LOGGER.info("Found {} with score {} and id {}", hit.source(), hit.score(), hit.id()); - IndexData finalSearchedData = hit.source(); - finalSearchedData.setText("Updated document"); - BulkRequest request = new BulkRequest.Builder().operations( - o -> o.update(u -> u.index(indexName).id(hit.id()).document(finalSearchedData)) - ).refresh(Refresh.WaitFor).build(); - bulkResponse = client.bulk(request); - LOGGER.info("Bulk update response items: {}", bulkResponse.items().size()); } - searchResponse = search(client, indexName, "title", "Document"); - for (var hit : searchResponse.hits().hits()) { - LOGGER.info("Found {} with score {} and id {}", hit.source(), hit.score(), hit.id()); - } + LOGGER.info("Bulk update document"); + doc1.setText("Updated Document"); + BulkRequest request = new BulkRequest.Builder().operations(o -> o.update(u -> u.index(indexName).id("id1").document(doc1))) + .refresh(Refresh.WaitFor) + .build(); + bulkResponse = client.bulk(request); + LOGGER.info("Bulk update response items: {}", bulkResponse.items().size()); + LOGGER.info("Deleting index {}", indexName); DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest.Builder().index(indexName).build(); client.indices().delete(deleteIndexRequest); @@ -99,15 +99,4 @@ public static void main(String[] args) { LOGGER.error("Unexpected exception", e); } } - - public static SearchResponse search(OpenSearchClient client, String indexName, String field, String value) - throws IOException { - Query query = Query.of(qb -> qb.match(mb -> mb.field(field).query(fv -> fv.stringValue(value)))); - final SearchRequest.Builder searchReq = new SearchRequest.Builder().allowPartialSearchResults(false) - .index(List.of(indexName)) - .size(10) - .ignoreThrottled(false) - .query(query); - return client.search(searchReq.build(), IndexData.class); - } } From f4fe54a74d4204ccf88b0b7ca4a57cd229966713 Mon Sep 17 00:00:00 2001 From: Karthik Subramanian Date: Fri, 27 Oct 2023 14:54:14 -0400 Subject: [PATCH 9/9] removing unnecessary changes Signed-off-by: Karthik Subramanian --- .../src/main/java/org/opensearch/client/samples/Bulk.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/samples/src/main/java/org/opensearch/client/samples/Bulk.java b/samples/src/main/java/org/opensearch/client/samples/Bulk.java index 0407f8bc98..21f6e88727 100644 --- a/samples/src/main/java/org/opensearch/client/samples/Bulk.java +++ b/samples/src/main/java/org/opensearch/client/samples/Bulk.java @@ -70,20 +70,17 @@ public static void main(String[] args) { BulkResponse bulkResponse = client.bulk(bulkReq.build()); LOGGER.info("Bulk response items: {}", bulkResponse.items().size()); - Query query = Query.of(qb -> qb.match(mb -> mb.field("title").query(fv -> fv.stringValue("document")))); + Query query = Query.of(qb -> qb.match(mb -> mb.field("title").query(fv -> fv.stringValue("Document")))); final SearchRequest.Builder searchReq = new SearchRequest.Builder().allowPartialSearchResults(false) .index(List.of(indexName)) .size(10) + .source(sc -> sc.fetch(false)) .ignoreThrottled(false) .query(query); SearchResponse searchResponse = client.search(searchReq.build(), IndexData.class); LOGGER.info("Found {} documents", searchResponse.hits().hits().size()); - for (var hit : searchResponse.hits().hits()) { - LOGGER.info("Found {} with score {} and id {}", hit.source(), hit.score(), hit.id()); - } - LOGGER.info("Bulk update document"); doc1.setText("Updated Document"); BulkRequest request = new BulkRequest.Builder().operations(o -> o.update(u -> u.index(indexName).id("id1").document(doc1)))