From faebdf7453eb99bbba3eb2891ce9b5153313467e Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Fri, 3 Mar 2023 15:59:10 -0800 Subject: [PATCH] Adding bulk request example in user guide (#373) (#384) (cherry picked from commit 75c5e595f01014942482464d00a84311ea28f962) Signed-off-by: Vacha Shah Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- USER_GUIDE.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 186d22de6d..5d3f5ceec6 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -10,6 +10,7 @@ - [Index data](#index-data) - [Search for the documents](#search-for-the-documents) - [Search documents using a match query](#search-documents-using-a-match-query) + - [Bulk requests](#bulk-requests) - [Aggregations](#aggregations) - [Delete the document](#delete-the-document) - [Delete the index](#delete-the-index) @@ -131,6 +132,30 @@ for (int i = 0; i < searchResponse.hits().hits().size(); i++) { } ``` +## Bulk requests + +```java +ArrayList ops = new ArrayList<>(); +SimplePojo doc1 = new SimplePojo("Document 1", "The text of document 1"); +ops.add(new BulkOperation.Builder().index( + IndexOperation.of(io -> io.index(TEST_INDEX).id("id1").document(doc1)) +).build()); +SimplePojo doc2 = new SimplePojo("Document 2", "The text of document 2"); +ops.add(new BulkOperation.Builder().index( + IndexOperation.of(io -> io.index(TEST_INDEX).id("id2").document(doc2)) +).build()); +SimplePojo doc3 = getLongDoc("Long Document 3", 100000); +ops.add(new BulkOperation.Builder().index( + IndexOperation.of(io -> io.index(TEST_INDEX).id("id3").document(doc3)) +).build()); + +BulkRequest.Builder bulkReq = new BulkRequest.Builder() + .index(index) + .operations(ops) + .refresh(Refresh.WaitFor); +BulkResponse bulkResponse = client.bulk(bulkReq.build()); +``` + ## Aggregations ```java