Skip to content

Commit 6fd7ea7

Browse files
authored
HLRC: DRY up remaining CRUD docs (#34925)
This further applies the pattern set in #34125 to reduce copy-and-paste in the multi-document CRUD portion of the High Level REST Client docs. It also adds line wraps to snippets that are too wide to fit into the box when rendered in the docs, following up on the work started in #34163.
1 parent b093116 commit 6fd7ea7

File tree

8 files changed

+305
-421
lines changed

8 files changed

+305
-421
lines changed

buildSrc/src/main/resources/checkstyle_suppressions.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
Truly temporary suppressions suppression of snippets included in
2626
documentation that are so wide that they scroll.
2727
-->
28-
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]client[/\\]documentation[/\\]CRUDDocumentationIT.java" id="SnippetLength" />
2928
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]client[/\\]documentation[/\\]ClusterClientDocumentationIT.java" id="SnippetLength" />
3029
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]client[/\\]documentation[/\\]GraphDocumentationIT.java" id="SnippetLength" />
3130
<suppress files="client[/\\]rest-high-level[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]client[/\\]documentation[/\\]IndicesClientDocumentationIT.java" id="SnippetLength" />

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

Lines changed: 82 additions & 48 deletions
Large diffs are not rendered by default.
Lines changed: 67 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,45 @@
1-
[[java-rest-high-document-bulk]]
1+
--
2+
:api: bulk
3+
:request: BulkRequest
4+
:response: BulkResponse
5+
--
6+
7+
[id="{upid}-{api}"]
28
=== Bulk API
39

4-
NOTE: The Java High Level REST Client provides the <<java-rest-high-document-bulk-processor>> to assist with bulk requests
10+
NOTE: The Java High Level REST Client provides the
11+
<<{upid}-{api}-processor>> to assist with bulk requests.
512

6-
[[java-rest-high-document-bulk-request]]
13+
[id="{upid}-{api}-request"]
714
==== Bulk Request
815

9-
A `BulkRequest` can be used to execute multiple index, update and/or delete
16+
A +{request}+ can be used to execute multiple index, update and/or delete
1017
operations using a single request.
1118

1219
It requires at least one operation to be added to the Bulk request:
1320

1421
["source","java",subs="attributes,callouts,macros"]
1522
--------------------------------------------------
16-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-request]
23+
include-tagged::{doc-tests-file}[{api}-request]
1724
--------------------------------------------------
18-
<1> Creates the `BulkRequest`
19-
<2> Adds a first `IndexRequest` to the Bulk request. See <<java-rest-high-document-index>>
20-
for more information on how to build `IndexRequest`.
25+
<1> Creates the +{request}+
26+
<2> Adds a first `IndexRequest` to the Bulk request. See <<{upid}-index>> for
27+
more information on how to build `IndexRequest`.
2128
<3> Adds a second `IndexRequest`
2229
<4> Adds a third `IndexRequest`
2330

24-
WARNING: The Bulk API supports only documents encoded in JSON or SMILE. Providing documents
25-
in any other format will result in an error.
31+
WARNING: The Bulk API supports only documents encoded in JSON or SMILE.
32+
Providing documents in any other format will result in an error.
2633

27-
And different operation types can be added to the same `BulkRequest`:
34+
And different operation types can be added to the same +{request}+:
2835

2936
["source","java",subs="attributes,callouts,macros"]
3037
--------------------------------------------------
31-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-request-with-mixed-operations]
38+
include-tagged::{doc-tests-file}[{api}-request-with-mixed-operations]
3239
--------------------------------------------------
33-
<1> Adds a `DeleteRequest` to the `BulkRequest`. See <<java-rest-high-document-delete>>
40+
<1> Adds a `DeleteRequest` to the `BulkRequest`. See <<{upid}-delete>>
3441
for more information on how to build `DeleteRequest`.
35-
<2> Adds an `UpdateRequest` to the `BulkRequest`. See <<java-rest-high-document-update>>
42+
<2> Adds an `UpdateRequest` to the `BulkRequest`. See <<{upid}-update>>
3643
for more information on how to build `UpdateRequest`.
3744
<3> Adds an `IndexRequest` using the SMILE format
3845

@@ -41,102 +48,66 @@ The following arguments can optionally be provided:
4148

4249
["source","java",subs="attributes,callouts,macros"]
4350
--------------------------------------------------
44-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-request-timeout]
51+
include-tagged::{doc-tests-file}[{api}-request-timeout]
4552
--------------------------------------------------
4653
<1> Timeout to wait for the bulk request to be performed as a `TimeValue`
4754
<2> Timeout to wait for the bulk request to be performed as a `String`
4855

4956
["source","java",subs="attributes,callouts,macros"]
5057
--------------------------------------------------
51-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-request-refresh]
58+
include-tagged::{doc-tests-file}[{api}-request-refresh]
5259
--------------------------------------------------
5360
<1> Refresh policy as a `WriteRequest.RefreshPolicy` instance
5461
<2> Refresh policy as a `String`
5562

5663
["source","java",subs="attributes,callouts,macros"]
5764
--------------------------------------------------
58-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-request-active-shards]
65+
include-tagged::{doc-tests-file}[{api}-request-active-shards]
5966
--------------------------------------------------
6067
<1> Sets the number of shard copies that must be active before proceeding with
6168
the index/update/delete operations.
62-
<2> Number of shard copies provided as a `ActiveShardCount`: can be `ActiveShardCount.ALL`,
63-
`ActiveShardCount.ONE` or `ActiveShardCount.DEFAULT` (default)
64-
65-
66-
[[java-rest-high-document-bulk-sync]]
67-
==== Synchronous Execution
68-
69-
["source","java",subs="attributes,callouts,macros"]
70-
--------------------------------------------------
71-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-execute]
72-
--------------------------------------------------
73-
74-
[[java-rest-high-document-bulk-async]]
75-
==== Asynchronous Execution
69+
<2> Number of shard copies provided as a `ActiveShardCount`: can be
70+
`ActiveShardCount.ALL`, `ActiveShardCount.ONE` or
71+
`ActiveShardCount.DEFAULT` (default)
7672

77-
The asynchronous execution of a bulk request requires both the `BulkRequest`
78-
instance and an `ActionListener` instance to be passed to the asynchronous
79-
method:
73+
include::../execution.asciidoc[]
8074

81-
["source","java",subs="attributes,callouts,macros"]
82-
--------------------------------------------------
83-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-execute-async]
84-
--------------------------------------------------
85-
<1> The `BulkRequest` to execute and the `ActionListener` to use when
86-
the execution completes
87-
88-
The asynchronous method does not block and returns immediately. Once it is
89-
completed the `ActionListener` is called back using the `onResponse` method
90-
if the execution successfully completed or using the `onFailure` method if
91-
it failed.
92-
93-
A typical listener for `BulkResponse` looks like:
94-
95-
["source","java",subs="attributes,callouts,macros"]
96-
--------------------------------------------------
97-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-execute-listener]
98-
--------------------------------------------------
99-
<1> Called when the execution is successfully completed. The response is
100-
provided as an argument and contains a list of individual results for each
101-
operation that was executed. Note that one or more operations might have
102-
failed while the others have been successfully executed.
103-
<2> Called when the whole `BulkRequest` fails. In this case the raised
104-
exception is provided as an argument and no operation has been executed.
105-
106-
[[java-rest-high-document-bulk-response]]
75+
[id="{upid}-{api}-response"]
10776
==== Bulk Response
10877

109-
The returned `BulkResponse` contains information about the executed operations and
78+
The returned +{response}+ contains information about the executed operations and
11079
allows to iterate over each result as follows:
11180

11281
["source","java",subs="attributes,callouts,macros"]
11382
--------------------------------------------------
114-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-response]
83+
include-tagged::{doc-tests-file}[{api}-response]
11584
--------------------------------------------------
11685
<1> Iterate over the results of all operations
117-
<2> Retrieve the response of the operation (successful or not), can be `IndexResponse`,
118-
`UpdateResponse` or `DeleteResponse` which can all be seen as `DocWriteResponse` instances
86+
<2> Retrieve the response of the operation (successful or not), can be
87+
`IndexResponse`, `UpdateResponse` or `DeleteResponse` which can all be seen as
88+
`DocWriteResponse` instances
11989
<3> Handle the response of an index operation
12090
<4> Handle the response of a update operation
12191
<5> Handle the response of a delete operation
12292

123-
The Bulk response provides a method to quickly check if one or more operation has failed:
93+
The Bulk response provides a method to quickly check if one or more operation
94+
has failed:
12495
["source","java",subs="attributes,callouts,macros"]
12596
--------------------------------------------------
126-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-has-failures]
97+
include-tagged::{doc-tests-file}[{api}-has-failures]
12798
--------------------------------------------------
12899
<1> This method returns `true` if at least one operation failed
129100

130-
In such situation it is necessary to iterate over all operation results in order to check
131-
if the operation failed, and if so, retrieve the corresponding failure:
101+
In such situation it is necessary to iterate over all operation results in order
102+
to check if the operation failed, and if so, retrieve the corresponding failure:
132103
["source","java",subs="attributes,callouts,macros"]
133104
--------------------------------------------------
134-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-errors]
105+
include-tagged::{doc-tests-file}[{api}-errors]
135106
--------------------------------------------------
136107
<1> Indicate if a given operation failed
137108
<2> Retrieve the failure of the failed operation
138109

139-
[[java-rest-high-document-bulk-processor]]
110+
[id="{upid}-{api}-processor"]
140111
==== Bulk Processor
141112

142113
The `BulkProcessor` simplifies the usage of the Bulk API by providing
@@ -146,29 +117,30 @@ transparently executed as they are added to the processor.
146117
In order to execute the requests, the `BulkProcessor` requires the following
147118
components:
148119

149-
`RestHighLevelClient`:: This client is used to execute the `BulkRequest`
120+
`RestHighLevelClient`:: This client is used to execute the +{request}+
150121
and to retrieve the `BulkResponse`
151122
`BulkProcessor.Listener`:: This listener is called before and after
152-
every `BulkRequest` execution or when a `BulkRequest` failed
123+
every +{request}+ execution or when a +{request}+ failed
153124

154-
Then the `BulkProcessor.builder` method can be used to build a new `BulkProcessor`:
125+
Then the `BulkProcessor.builder` method can be used to build a new
126+
`BulkProcessor`:
155127
["source","java",subs="attributes,callouts,macros"]
156128
--------------------------------------------------
157-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-processor-init]
129+
include-tagged::{doc-tests-file}[{api}-processor-init]
158130
--------------------------------------------------
159131
<1> Create the `BulkProcessor.Listener`
160-
<2> This method is called before each execution of a `BulkRequest`
161-
<3> This method is called after each execution of a `BulkRequest`
162-
<4> This method is called when a `BulkRequest` failed
132+
<2> This method is called before each execution of a +{request}+
133+
<3> This method is called after each execution of a +{request}+
134+
<4> This method is called when a +{request}+ failed
163135
<5> Create the `BulkProcessor` by calling the `build()` method from
164136
the `BulkProcessor.Builder`. The `RestHighLevelClient.bulkAsync()`
165-
method will be used to execute the `BulkRequest` under the hood.
137+
method will be used to execute the +{request}+ under the hood.
166138

167-
The `BulkProcessor.Builder` provides methods to configure how the `BulkProcessor`
168-
should handle requests execution:
139+
The `BulkProcessor.Builder` provides methods to configure how the
140+
`BulkProcessor` should handle requests execution:
169141
["source","java",subs="attributes,callouts,macros"]
170142
--------------------------------------------------
171-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-processor-options]
143+
include-tagged::{doc-tests-file}[{api}-processor-options]
172144
--------------------------------------------------
173145
<1> Set when to flush a new bulk request based on the number of
174146
actions currently added (defaults to 1000, use -1 to disable it)
@@ -186,42 +158,41 @@ for more options.
186158
Once the `BulkProcessor` is created requests can be added to it:
187159
["source","java",subs="attributes,callouts,macros"]
188160
--------------------------------------------------
189-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-processor-add]
161+
include-tagged::{doc-tests-file}[{api}-processor-add]
190162
--------------------------------------------------
191163

192164
The requests will be executed by the `BulkProcessor`, which takes care of
193165
calling the `BulkProcessor.Listener` for every bulk request.
194166

195-
The listener provides methods to access to the `BulkRequest` and the `BulkResponse`:
167+
The listener provides methods to access to the +{request}+ and the +{response}+:
196168
["source","java",subs="attributes,callouts,macros"]
197169
--------------------------------------------------
198-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-processor-listener]
170+
include-tagged::{doc-tests-file}[{api}-processor-listener]
199171
--------------------------------------------------
200-
<1> Called before each execution of a `BulkRequest`, this method allows
201-
to know the number of operations that are going to be executed within the `BulkRequest`
202-
<2> Called after each execution of a `BulkRequest`, this method allows
203-
to know if the `BulkResponse` contains errors
204-
<3> Called if the `BulkRequest` failed, this method allows to know
172+
<1> Called before each execution of a +{request}+, this method allows to know
173+
the number of operations that are going to be executed within the +{request}+
174+
<2> Called after each execution of a +{request}+, this method allows to know if
175+
the +{response}+ contains errors
176+
<3> Called if the +{request}+ failed, this method allows to know
205177
the failure
206178

207179
Once all requests have been added to the `BulkProcessor`, its instance needs to
208180
be closed using one of the two available closing methods.
209181

210-
The `awaitClose()` method can be used to wait until all requests have been processed
211-
or the specified waiting time elapses:
182+
The `awaitClose()` method can be used to wait until all requests have been
183+
processed or the specified waiting time elapses:
212184
["source","java",subs="attributes,callouts,macros"]
213185
--------------------------------------------------
214-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-processor-await]
186+
include-tagged::{doc-tests-file}[{api}-processor-await]
215187
--------------------------------------------------
216188
<1> The method returns `true` if all bulk requests completed and `false` if the
217189
waiting time elapsed before all the bulk requests completed
218190

219191
The `close()` method can be used to immediately close the `BulkProcessor`:
220192
["source","java",subs="attributes,callouts,macros"]
221193
--------------------------------------------------
222-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[bulk-processor-close]
194+
include-tagged::{doc-tests-file}[{api}-processor-close]
223195
--------------------------------------------------
224196

225-
Both methods flush the requests added to the processor before closing the processor
226-
and also forbid any new request to be added to it.
227-
197+
Both methods flush the requests added to the processor before closing the
198+
processor and also forbid any new request to be added to it.

0 commit comments

Comments
 (0)