Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an example for bulk update operation #690

Merged
merged 9 commits into from
Oct 27, 2023
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
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
Loading