From 25bd4cf19dc2bd7e31596865cf75f031104d6dfa Mon Sep 17 00:00:00 2001 From: Karthik Subramanian Date: Fri, 27 Oct 2023 16:48:48 -0400 Subject: [PATCH] Adding an example for bulk update operation (#690) * Adding an example for bulk update operation Signed-off-by: Karthik Subramanian * updated the changelog.md Signed-off-by: Karthik Subramanian * changes made by spotlessApply Signed-off-by: Karthik Subramanian * removing CommonUtil based on review comments Signed-off-by: Karthik Subramanian * reverting files to original state Signed-off-by: Karthik Subramanian * changes by spotlessApply Signed-off-by: Karthik Subramanian * removing static fields and unnecessary waits Signed-off-by: Karthik Subramanian * changes as per review comments Signed-off-by: Karthik Subramanian * removing unnecessary changes Signed-off-by: Karthik Subramanian --------- Signed-off-by: Karthik Subramanian --- CHANGELOG.md | 3 ++- .../main/java/org/opensearch/client/samples/Bulk.java | 9 +++++++++ 2 files changed, 11 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 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..21f6e88727 100644 --- a/samples/src/main/java/org/opensearch/client/samples/Bulk.java +++ b/samples/src/main/java/org/opensearch/client/samples/Bulk.java @@ -77,9 +77,18 @@ public static void main(String[] args) { .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()); + 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);