Skip to content

Commit

Permalink
Adding an example for bulk update operation (#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>
(cherry picked from commit 25bd4cf)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Oct 27, 2023
1 parent 42b592c commit 92557cc
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 @@ -7,7 +7,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### 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 92557cc

Please sign in to comment.