Skip to content

Commit

Permalink
Adding an example for bulk update operation (opensearch-project#690)
Browse files Browse the repository at this point in the history
* Adding an example for bulk update operation

Signed-off-by: Karthik Subramanian <karthiks3000@yahoo.com>

* updated the changelog.md

Signed-off-by: Karthik Subramanian <karthiks3000@yahoo.com>

* changes made by spotlessApply

Signed-off-by: Karthik Subramanian <karthiks3000@yahoo.com>

* removing CommonUtil based on review comments

Signed-off-by: Karthik Subramanian <karthiks3000@yahoo.com>

* reverting files to original state

Signed-off-by: Karthik Subramanian <karthiks3000@yahoo.com>

* changes by spotlessApply

Signed-off-by: Karthik Subramanian <karthiks3000@yahoo.com>

* removing static fields and unnecessary waits

Signed-off-by: Karthik Subramanian <karthiks3000@yahoo.com>

* changes as per review comments

Signed-off-by: Karthik Subramanian <karthiks3000@yahoo.com>

* removing unnecessary changes

Signed-off-by: Karthik Subramanian <karthiks3000@yahoo.com>

---------

Signed-off-by: Karthik Subramanian <karthiks3000@yahoo.com>
  • Loading branch information
karthiks3000 authored Oct 27, 2023
1 parent 9408cc2 commit 25bd4cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions samples/src/main/java/org/opensearch/client/samples/Bulk.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,18 @@ public static void main(String[] args) {
.source(sc -> sc.fetch(false))
.ignoreThrottled(false)
.query(query);

SearchResponse<IndexData> 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);
Expand Down

0 comments on commit 25bd4cf

Please sign in to comment.