Skip to content

Commit 7df652a

Browse files
authored
Docs: HLRC: refactor bulk, migrate and reindex apis #35620
fix typos and refactor to DRY up documentation for bulk, reindex and migration apis relates #35345 backport of #35413
1 parent 669e606 commit 7df652a

File tree

5 files changed

+66
-23
lines changed

5 files changed

+66
-23
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,19 @@ 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()
116+
.submitReindexTask(reindexRequest, RequestOptions.DEFAULT); // <2>
117+
118+
String taskId = reindexSubmission.getTask(); // <3>
119+
// end::submit-reindex-task
116120

117-
BooleanSupplier hasUpgradeCompleted = checkCompletionStatus(reindexSubmission.getTask());
121+
BooleanSupplier hasUpgradeCompleted = checkCompletionStatus(taskId);
118122
awaitBusy(hasUpgradeCompleted);
119123
}
120124
}

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

Lines changed: 22 additions & 3 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

@@ -70,6 +70,25 @@ the index/update/delete operations.
7070
`ActiveShardCount.ALL`, `ActiveShardCount.ONE` or
7171
`ActiveShardCount.DEFAULT` (default)
7272

73+
["source","java",subs="attributes,callouts,macros"]
74+
--------------------------------------------------
75+
include-tagged::{doc-tests-file}[{api}-request-pipeline]
76+
--------------------------------------------------
77+
<1> Global pipelineId used on all sub requests, unless overridden on a sub request
78+
79+
["source","java",subs="attributes,callouts,macros"]
80+
--------------------------------------------------
81+
include-tagged::{doc-tests-file}[{api}-request-routing]
82+
--------------------------------------------------
83+
<1> Global routingId used on all sub requests, unless overridden on a sub request
84+
85+
["source","java",subs="attributes,callouts,macros"]
86+
--------------------------------------------------
87+
include-tagged::{doc-tests-file}[{api}-request-index-type]
88+
--------------------------------------------------
89+
<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 +{request}+ creation.
91+
7392
include::../execution.asciidoc[]
7493

7594
[id="{upid}-{api}-response"]
@@ -148,7 +167,7 @@ actions currently added (defaults to 1000, use -1 to disable it)
148167
actions currently added (defaults to 5Mb, use -1 to disable it)
149168
<3> Set the number of concurrent requests allowed to be executed
150169
(default to 1, use 0 to only allow the execution of a single request)
151-
<4> Set a flush interval flushing any `BulkRequest` pending if the
170+
<4> Set a flush interval flushing any +{request}+ pending if the
152171
interval passes (defaults to not set)
153172
<5> Set a constant back off policy that initially waits for 1 second
154173
and retries up to 3 times. See `BackoffPolicy.noBackoff()`,

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

Lines changed: 15 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,19 @@ 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+
<1> A +{request}+ is constructed the same way as for the synchronous method
170+
<2> A submit method returns a `TaskSubmissionResponse` which contains a task identifier.
171+
<3> The task identifier can be used to get `response` from a completed task.
172+
160173
[id="{upid}-{api}-response"]
161174
==== Reindex Response
162175

docs/java-rest/high-level/index.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ the same response objects.
2525
--
2626

2727
:doc-tests: {docdir}/../../client/rest-high-level/src/test/java/org/elasticsearch/client/documentation
28+
:hlrc-tests: {docdir}/../../client/rest-high-level/src/test/java/org/elasticsearch/client
2829

2930
include::getting-started.asciidoc[]
3031
include::supported-apis.asciidoc[]
Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1+
--
2+
:api: upgrade
3+
:request: IndexUpgradeRequest
4+
:response: BulkByScrollResponse
5+
:submit_response: IndexUpgradeSubmissionResponse
6+
:doc-tests-file: {doc-tests}/MigrationClientDocumentationIT.java
7+
--
8+
19
[[java-rest-high-migration-upgrade]]
210
=== Migration Upgrade
311

412
[[java-rest-high-migraton-upgrade-request]]
513
==== Index Upgrade Request
614

7-
An `IndexUpgradeRequest` requires an index argument. Only one index at the time should be upgraded:
15+
An +{request}+ requires an index argument. Only one index at the time should be upgraded:
816

917
["source","java",subs="attributes,callouts,macros"]
1018
--------------------------------------------------
11-
include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[upgrade-request]
19+
include-tagged::{doc-tests-file}[{api}-request]
1220
--------------------------------------------------
1321
<1> Create a new request instance
1422

@@ -17,39 +25,37 @@ include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[upgrade-request]
1725

1826
["source","java",subs="attributes,callouts,macros"]
1927
--------------------------------------------------
20-
include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[upgrade-execute]
28+
include-tagged::{doc-tests-file}[{api}-execute]
2129
--------------------------------------------------
2230

2331
[[java-rest-high-migration-upgrade-response]]
2432
==== Response
25-
The returned `BulkByScrollResponse` contains information about the executed operation
33+
The returned +{response}+ contains information about the executed operation
2634

2735

2836
[[java-rest-high-migraton-async-upgrade-request]]
2937
==== Asynchronous Execution
3038

31-
The asynchronous execution of a upgrade request requires both the `IndexUpgradeRequest`
39+
The asynchronous execution of an upgrade request requires both the +{request}+
3240
instance and an `ActionListener` instance to be passed to the asynchronous
3341
method:
3442

35-
A typical listener for `BulkResponse` looks like:
36-
3743
["source","java",subs="attributes,callouts,macros"]
3844
--------------------------------------------------
39-
include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[upgrade-async-listener]
45+
include-tagged::{doc-tests-file}[{api}-async-listener]
4046
--------------------------------------------------
4147
<1> Called when the execution is successfully completed. The response is
4248
provided as an argument and contains a list of individual results for each
4349
operation that was executed. Note that one or more operations might have
4450
failed while the others have been successfully executed.
45-
<2> Called when the whole `IndexUpgradeRequest` fails. In this case the raised
51+
<2> Called when the whole +{request}+ fails. In this case the raised
4652
exception is provided as an argument and no operation has been executed.
4753

4854
["source","java",subs="attributes,callouts,macros"]
4955
--------------------------------------------------
50-
include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[upgrade-async-execute]
56+
include-tagged::{doc-tests-file}[{api}-async-execute]
5157
--------------------------------------------------
52-
<1> The `IndexUpgradeRequest` to execute and the `ActionListener` to use when
58+
<1> The +{request}+ to execute and the `ActionListener` to use when
5359
the execution completes
5460

5561
The asynchronous method does not block and returns immediately. Once it is
@@ -59,11 +65,11 @@ it failed.
5965

6066

6167
=== Migration Upgrade with Task API
62-
Submission of upgrade request task will requires the `IndexUpgradeRequest` and will return
63-
`IndexUpgradeSubmissionResponse`. The `IndexUpgradeSubmissionResponse` can later be use to fetch
68+
Submission of upgrade request task will requires the +{request}+ and will return
69+
+{submit_response}+. The +{submit_response}+ can later be use to fetch
6470
TaskId and query the Task API for results.
6571

6672
["source","java",subs="attributes,callouts,macros"]
6773
--------------------------------------------------
68-
include-tagged::{doc-tests}/MigrationClientDocumentationIT.java[upgrade-task-api]
74+
include-tagged::{doc-tests-file}[{api}-task-api]
6975
--------------------------------------------------

0 commit comments

Comments
 (0)