Skip to content

Commit 8082b4a

Browse files
authored
Docs: DRY up HLRC index docs (#34157)
Use tricks pioneered in #34125 to shorted asciidoc for the index API's docs. Also slightly shorten the supported-api docs file.
1 parent d25e3ef commit 8082b4a

File tree

3 files changed

+53
-92
lines changed

3 files changed

+53
-92
lines changed

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,8 @@
9595
import static org.hamcrest.Matchers.not;
9696

9797
/**
98-
* This class is used to generate the Java CRUD API documentation.
99-
* You need to wrap your code between two tags like:
100-
* // tag::example
101-
* // end::example
102-
*
103-
* Where example is your tag name.
104-
*
105-
* Then in the documentation, you can extract what is between tag and end tags with
106-
* ["source","java",subs="attributes,callouts,macros"]
107-
* --------------------------------------------------
108-
* include-tagged::{doc-tests}/CRUDDocumentationIT.java[example]
109-
* --------------------------------------------------
110-
*
111-
* The column width of the code block is 84. If the code contains a line longer
112-
* than 84, the line will be cut and a horizontal scroll bar will be displayed.
113-
* (the code indentation of the tag is not included in the width)
98+
* Documentation for CRUD APIs in the high level java client.
99+
* Code wrapped in {@code tag} and {@code end} tags is included in the docs.
114100
*/
115101
public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
116102

Lines changed: 26 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
[[java-rest-high-document-index]]
1+
--
2+
:api: index
3+
:request: IndexRequest
4+
:response: IndexResponse
5+
--
6+
7+
[id="{upid}-{api}"]
28
=== Index API
39

4-
[[java-rest-high-document-index-request]]
10+
[id="{upid}-{api}-request"]
511
==== Index Request
612

7-
An `IndexRequest` requires the following arguments:
13+
An +{request}+ requires the following arguments:
814

915
["source","java",subs="attributes,callouts,macros"]
1016
--------------------------------------------------
11-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[index-request-string]
17+
include-tagged::{doc-tests-file}[{api}-request-string]
1218
--------------------------------------------------
1319
<1> Index
1420
<2> Type
@@ -21,21 +27,21 @@ The document source can be provided in different ways in addition to the
2127

2228
["source","java",subs="attributes,callouts,macros"]
2329
--------------------------------------------------
24-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[index-request-map]
30+
include-tagged::{doc-tests-file}[{api}-request-map]
2531
--------------------------------------------------
2632
<1> Document source provided as a `Map` which gets automatically converted
2733
to JSON format
2834

2935
["source","java",subs="attributes,callouts,macros"]
3036
--------------------------------------------------
31-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[index-request-xcontent]
37+
include-tagged::{doc-tests-file}[{api}-request-xcontent]
3238
--------------------------------------------------
3339
<1> Document source provided as an `XContentBuilder` object, the Elasticsearch
3440
built-in helpers to generate JSON content
3541

3642
["source","java",subs="attributes,callouts,macros"]
3743
--------------------------------------------------
38-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[index-request-shortcut]
44+
include-tagged::{doc-tests-file}[{api}-request-shortcut]
3945
--------------------------------------------------
4046
<1> Document source provided as `Object` key-pairs, which gets converted to
4147
JSON format
@@ -45,95 +51,60 @@ The following arguments can optionally be provided:
4551

4652
["source","java",subs="attributes,callouts,macros"]
4753
--------------------------------------------------
48-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[index-request-routing]
54+
include-tagged::{doc-tests-file}[{api}-request-routing]
4955
--------------------------------------------------
5056
<1> Routing value
5157

5258
["source","java",subs="attributes,callouts,macros"]
5359
--------------------------------------------------
54-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[index-request-timeout]
60+
include-tagged::{doc-tests-file}[{api}-request-timeout]
5561
--------------------------------------------------
5662
<1> Timeout to wait for primary shard to become available as a `TimeValue`
5763
<2> Timeout to wait for primary shard to become available as a `String`
5864

5965
["source","java",subs="attributes,callouts,macros"]
6066
--------------------------------------------------
61-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[index-request-refresh]
67+
include-tagged::{doc-tests-file}[{api}-request-refresh]
6268
--------------------------------------------------
6369
<1> Refresh policy as a `WriteRequest.RefreshPolicy` instance
6470
<2> Refresh policy as a `String`
6571

6672
["source","java",subs="attributes,callouts,macros"]
6773
--------------------------------------------------
68-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[index-request-version]
74+
include-tagged::{doc-tests-file}[{api}-request-version]
6975
--------------------------------------------------
7076
<1> Version
7177

7278
["source","java",subs="attributes,callouts,macros"]
7379
--------------------------------------------------
74-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[index-request-version-type]
80+
include-tagged::{doc-tests-file}[{api}-request-version-type]
7581
--------------------------------------------------
7682
<1> Version type
7783

7884
["source","java",subs="attributes,callouts,macros"]
7985
--------------------------------------------------
80-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[index-request-op-type]
86+
include-tagged::{doc-tests-file}[{api}-request-op-type]
8187
--------------------------------------------------
8288
<1> Operation type provided as an `DocWriteRequest.OpType` value
8389
<2> Operation type provided as a `String`: can be `create` or `update` (default)
8490

8591
["source","java",subs="attributes,callouts,macros"]
8692
--------------------------------------------------
87-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[index-request-pipeline]
93+
include-tagged::{doc-tests-file}[{api}-request-pipeline]
8894
--------------------------------------------------
8995
<1> The name of the ingest pipeline to be executed before indexing the document
9096

91-
[[java-rest-high-document-index-sync]]
92-
==== Synchronous Execution
93-
94-
["source","java",subs="attributes,callouts,macros"]
95-
--------------------------------------------------
96-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[index-execute]
97-
--------------------------------------------------
98-
99-
[[java-rest-high-document-index-async]]
100-
==== Asynchronous Execution
101-
102-
The asynchronous execution of an index request requires both the `IndexRequest`
103-
instance and an `ActionListener` instance to be passed to the asynchronous
104-
method:
105-
106-
["source","java",subs="attributes,callouts,macros"]
107-
--------------------------------------------------
108-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[index-execute-async]
109-
--------------------------------------------------
110-
<1> The `IndexRequest` to execute and the `ActionListener` to use when
111-
the execution completes
112-
113-
The asynchronous method does not block and returns immediately. Once it is
114-
completed the `ActionListener` is called back using the `onResponse` method
115-
if the execution successfully completed or using the `onFailure` method if
116-
it failed.
117-
118-
A typical listener for `IndexResponse` looks like:
119-
120-
["source","java",subs="attributes,callouts,macros"]
121-
--------------------------------------------------
122-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[index-execute-listener]
123-
--------------------------------------------------
124-
<1> Called when the execution is successfully completed. The response is
125-
provided as an argument
126-
<2> Called in case of failure. The raised exception is provided as an argument
97+
include::../execution.asciidoc[]
12798

128-
[[java-rest-high-document-index-response]]
99+
[id="{upid}-{api}-response"]
129100
==== Index Response
130101

131-
The returned `IndexResponse` allows to retrieve information about the executed
102+
The returned +{response}+ allows to retrieve information about the executed
132103
operation as follows:
133104

134105
["source","java",subs="attributes,callouts,macros"]
135106
--------------------------------------------------
136-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[index-response]
107+
include-tagged::{doc-tests-file}[{api}-response]
137108
--------------------------------------------------
138109
<1> Handle (if needed) the case where the document was created for the first
139110
time
@@ -148,7 +119,7 @@ be thrown:
148119

149120
["source","java",subs="attributes,callouts,macros"]
150121
--------------------------------------------------
151-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[index-conflict]
122+
include-tagged::{doc-tests-file}[{api}-conflict]
152123
--------------------------------------------------
153124
<1> The raised exception indicates that a version conflict error was returned
154125

@@ -157,6 +128,6 @@ same index, type and id already existed:
157128

158129
["source","java",subs="attributes,callouts,macros"]
159130
--------------------------------------------------
160-
include-tagged::{doc-tests}/CRUDDocumentationIT.java[index-optype]
131+
include-tagged::{doc-tests-file}[{api}-optype]
161132
--------------------------------------------------
162133
<1> The raised exception indicates that a version conflict error was returned

docs/java-rest/high-level/supported-apis.asciidoc

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,26 @@
22

33
== Document APIs
44

5+
:upid: {mainid}-document
6+
:doc-tests-file: {doc-tests}/CRUDDocumentationIT.java
7+
58
The Java High Level REST Client supports the following Document APIs:
69

710
[[single-doc]]
811
Single document APIs::
9-
* <<java-rest-high-document-index>>
10-
* <<java-rest-high-document-get>>
11-
* <<java-rest-high-document-delete>>
12-
* <<java-rest-high-document-update>>
12+
* <<{upid}-index>>
13+
* <<{upid}-get>>
14+
* <<{upid}-delete>>
15+
* <<{upid}-update>>
1316

1417
[[multi-doc]]
1518
Multi-document APIs::
16-
* <<java-rest-high-document-bulk>>
17-
* <<java-rest-high-document-multi-get>>
18-
* <<java-rest-high-document-reindex>>
19-
* <<java-rest-high-document-update-by-query>>
20-
* <<java-rest-high-document-delete-by-query>>
21-
* <<java-rest-high-document-reindex-rethrottle>>
19+
* <<{upid}-bulk>>
20+
* <<{upid}-multi-get>>
21+
* <<{upid}-reindex>>
22+
* <<{upid}-update-by-query>>
23+
* <<{upid}-delete-by-query>>
24+
* <<{upid}-reindex-rethrottle>>
2225

2326
include::document/index.asciidoc[]
2427
include::document/get.asciidoc[]
@@ -34,20 +37,21 @@ include::document/reindex-rethrottle.asciidoc[]
3437

3538
== Search APIs
3639

40+
:upid: {mainid}
41+
:doc-tests-file: {doc-tests}/SearchDocumentationIT.java
42+
3743
The Java High Level REST Client supports the following Search APIs:
3844

39-
* <<java-rest-high-search>>
40-
* <<java-rest-high-search-scroll>>
41-
* <<java-rest-high-clear-scroll>>
42-
* <<java-rest-high-search-template>>
43-
* <<java-rest-high-multi-search-template>>
44-
* <<java-rest-high-multi-search>>
45-
* <<java-rest-high-field-caps>>
46-
* <<java-rest-high-rank-eval>>
47-
* <<java-rest-high-explain>>
45+
* <<{upid}-search>>
46+
* <<{upid}-search-scroll>>
47+
* <<{upid}-clear-scroll>>
48+
* <<{upid}-search-template>>
49+
* <<{upid}-multi-search-template>>
50+
* <<{upid}-multi-search>>
51+
* <<{upid}-field-caps>>
52+
* <<{upid}-rank-eval>>
53+
* <<{upid}-explain>>
4854

49-
:upid: {mainid}
50-
:doc-tests-file: {doc-tests}/SearchDocumentationIT.java
5155
include::search/search.asciidoc[]
5256
include::search/scroll.asciidoc[]
5357
include::search/multi-search.asciidoc[]

0 commit comments

Comments
 (0)