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

[Backport 2.x] Adding an example for bulk update operation #693

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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