Skip to content

Commit 3fbfbc9

Browse files
committed
refactor bulk and reindex apis
1 parent 5c84708 commit 3fbfbc9

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/ReindexIT.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,18 @@ public void testReindexTask() throws IOException, InterruptedException {
106106
);
107107
}
108108
{
109-
ReindexRequest reindexRequest = new ReindexRequest();
109+
// tag::submit-reindex-task
110+
ReindexRequest reindexRequest = new ReindexRequest(); // <1>
110111
reindexRequest.setSourceIndices(sourceIndex);
111112
reindexRequest.setDestIndex(destinationIndex);
112-
reindexRequest.setSourceQuery(new IdsQueryBuilder().addIds("1").types("type"));
113113
reindexRequest.setRefresh(true);
114114

115-
TaskSubmissionResponse reindexSubmission = highLevelClient().submitReindexTask(reindexRequest, RequestOptions.DEFAULT);
115+
TaskSubmissionResponse reindexSubmission = highLevelClient().submitReindexTask(reindexRequest, RequestOptions.DEFAULT); // <2>
116+
117+
String taskId = reindexSubmission.getTask(); // <3>
118+
// end::submit-reindex-task
116119

117-
BooleanSupplier hasUpgradeCompleted = checkCompletionStatus(reindexSubmission.getTask());
120+
BooleanSupplier hasUpgradeCompleted = checkCompletionStatus(taskId);
118121
awaitBusy(hasUpgradeCompleted);
119122
}
120123
}

docs/java-rest/high-level/document/bulk.asciidoc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ And different operation types can be added to the same +{request}+:
3737
--------------------------------------------------
3838
include-tagged::{doc-tests-file}[{api}-request-with-mixed-operations]
3939
--------------------------------------------------
40-
<1> Adds a `DeleteRequest` to the `BulkRequest`. See <<{upid}-delete>>
40+
<1> Adds a `DeleteRequest` to the +{request}+. See <<{upid}-delete>>
4141
for more information on how to build `DeleteRequest`.
42-
<2> Adds an `UpdateRequest` to the `BulkRequest`. See <<{upid}-update>>
42+
<2> Adds an `UpdateRequest` to the +{request}+. See <<{upid}-update>>
4343
for more information on how to build `UpdateRequest`.
4444
<3> Adds an `IndexRequest` using the SMILE format
4545

@@ -72,22 +72,22 @@ the index/update/delete operations.
7272

7373
["source","java",subs="attributes,callouts,macros"]
7474
--------------------------------------------------
75-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-request-pipeline]
75+
include-tagged::{doc-tests-file}[{api}-request-pipeline]
7676
--------------------------------------------------
7777
<1> Global pipelineId used on all sub requests, unless overridden on a sub request
7878

7979
["source","java",subs="attributes,callouts,macros"]
8080
--------------------------------------------------
81-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-request-routing]
81+
include-tagged::{doc-tests-file}[{api}-request-routing]
8282
--------------------------------------------------
8383
<1> Global routingId used on all sub requests, unless overridden on a sub request
8484

8585
["source","java",subs="attributes,callouts,macros"]
8686
--------------------------------------------------
87-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-request-index-type]
87+
include-tagged::{doc-tests-file}[{api}-request-index-type]
8888
--------------------------------------------------
8989
<1> A bulk request with global index and type used on all sub requests, unless overridden on a sub request.
90-
Both parameters are @Nullable and can only be set during BulkRequest creation.
90+
Both parameters are @Nullable and can only be set during +{request}+ creation.
9191

9292
include::../execution.asciidoc[]
9393

@@ -167,7 +167,7 @@ actions currently added (defaults to 1000, use -1 to disable it)
167167
actions currently added (defaults to 5Mb, use -1 to disable it)
168168
<3> Set the number of concurrent requests allowed to be executed
169169
(default to 1, use 0 to only allow the execution of a single request)
170-
<4> Set a flush interval flushing any `BulkRequest` pending if the
170+
<4> Set a flush interval flushing any +{request}+ pending if the
171171
interval passes (defaults to not set)
172172
<5> Set a constant back off policy that initially waits for 1 second
173173
and retries up to 3 times. See `BackoffPolicy.noBackoff()`,

docs/java-rest/high-level/document/reindex.asciidoc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[id="{upid}-{api}-request"]
1111
==== Reindex Request
1212

13-
A +{request} can be used to copy documents from one or more indexes into a
13+
A +{request}+ can be used to copy documents from one or more indexes into a
1414
destination index.
1515

1616
It requires an existing source index and a target index which may or may not exist pre-request. Reindex does not attempt
@@ -100,7 +100,7 @@ include-tagged::{doc-tests-file}[{api}-request-sort]
100100
<1> add descending sort to`field1`
101101
<2> add ascending sort to `field2`
102102

103-
+{request} also supports a `script` that modifies the document. It allows you to
103+
+{request}+ also supports a `script` that modifies the document. It allows you to
104104
also change the document's metadata. The following example illustrates that.
105105

106106
["source","java",subs="attributes,callouts,macros"]
@@ -157,6 +157,20 @@ include-tagged::{doc-tests-file}[{api}-request-refresh]
157157

158158
include::../execution.asciidoc[]
159159

160+
[id="{upid}-{api}-task-submission"]
161+
==== Reindex task submission
162+
It is also possible to submit a +{request}+ and not wait for it completion with the use of Task API. This is an equivalent of a REST request
163+
with wait_for_completion flag set to false.
164+
165+
["source","java",subs="attributes,callouts,macros"]
166+
--------------------------------------------------
167+
include-tagged::{hlrc-tests}/ReindexIT.java[submit-reindex-task]
168+
--------------------------------------------------
169+
170+
<1> A +{request}+ is constructed the same way as for the synchronous method
171+
<2> A submit method returns a `TaskSubmissionResponse` which contains a task identifier.
172+
<3> The task identifier can be used to get `response` from a completed task.
173+
160174
[id="{upid}-{api}-response"]
161175
==== Reindex Response
162176

0 commit comments

Comments
 (0)