Skip to content

Commit 4c2626c

Browse files
committed
add docs for open index
1 parent 4760c5d commit 4c2626c

File tree

5 files changed

+158
-1
lines changed

5 files changed

+158
-1
lines changed

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

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
2929
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
3030
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
31+
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
32+
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
3133
import org.elasticsearch.action.support.ActiveShardCount;
3234
import org.elasticsearch.action.support.IndicesOptions;
3335
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
@@ -193,6 +195,70 @@ public void onFailure(Exception e) {
193195
}
194196
}
195197

198+
public void openIndex() throws IOException {
199+
RestHighLevelClient client = highLevelClient();
200+
201+
{
202+
CreateIndexResponse createIndexResponse = client.indices().createIndex(new CreateIndexRequest("index"));
203+
assertTrue(createIndexResponse.isAcknowledged());
204+
}
205+
206+
{
207+
// tag::open-index-request
208+
OpenIndexRequest request = new OpenIndexRequest("index"); // <1>
209+
// end::open-index-request
210+
211+
// tag::open-index-request-timeout
212+
request.timeout(TimeValue.timeValueMinutes(2)); // <1>
213+
request.timeout("2m"); // <2>
214+
// end::open-index-request-timeout
215+
// tag::open-index-request-masterTimeout
216+
request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1>
217+
request.masterNodeTimeout("1m"); // <2>
218+
// end::open-index-request-masterTimeout
219+
220+
// tag::open-index-request-indicesOptions
221+
request.indicesOptions(IndicesOptions.strictExpandOpen()); // <1>
222+
// end::open-index-request-indicesOptions
223+
224+
// tag::open-index-execute
225+
OpenIndexResponse openIndexResponse = client.indices().openIndex(request);
226+
// end::open-index-execute
227+
228+
// tag::open-index-response
229+
boolean acknowledged = openIndexResponse.isAcknowledged(); // <1>
230+
// end::open-index-response
231+
assertTrue(acknowledged);
232+
233+
// tag::open-index-execute-async
234+
client.indices().openIndexAsync(request, new ActionListener<OpenIndexResponse>() {
235+
@Override
236+
public void onResponse(OpenIndexResponse openIndexResponse) {
237+
// <1>
238+
}
239+
240+
@Override
241+
public void onFailure(Exception e) {
242+
// <2>
243+
}
244+
});
245+
// end::open-index-execute-async
246+
}
247+
248+
{
249+
// tag::open-index-notfound
250+
try {
251+
OpenIndexRequest request = new OpenIndexRequest("does_not_exist");
252+
client.indices().openIndex(request);
253+
} catch (ElasticsearchException exception) {
254+
if (exception.status() == RestStatus.BAD_REQUEST) {
255+
// <1>
256+
}
257+
}
258+
// end::open-index-notfound
259+
}
260+
}
261+
196262
public void closeIndex() throws IOException {
197263
RestHighLevelClient client = highLevelClient();
198264

@@ -231,7 +297,7 @@ public void closeIndex() throws IOException {
231297
// tag::close-index-execute-async
232298
client.indices().closeIndexAsync(request, new ActionListener<CloseIndexResponse>() {
233299
@Override
234-
public void onResponse(CloseIndexResponse deleteIndexResponse) {
300+
public void onResponse(CloseIndexResponse closeIndexResponse) {
235301
// <1>
236302
}
237303

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[close-index-reques
3131
<1> Timeout to connect to the master node as a `TimeValue`
3232
<2> Timeout to connect to the master node as a `String`
3333

34+
["source","java",subs="attributes,callouts,macros"]
35+
--------------------------------------------------
36+
include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[close-index-request-indicesOptions]
37+
--------------------------------------------------
38+
<1> Setting `IndicesOptions` controls how unavailable indices are resolved and
39+
how wildcard expressions are expanded
40+
3441
[[java-rest-high-close-index-sync]]
3542
==== Synchronous Execution
3643

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ include::createindex.asciidoc[]
22

33
include::deleteindex.asciidoc[]
44

5+
include::open_index.asciidoc[]
6+
57
include::close_index.asciidoc[]
68

79
include::_index.asciidoc[]
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
[[java-rest-high-open-index]]
2+
=== Open Index API
3+
4+
[[java-rest-high-open-index-request]]
5+
==== Open Index Request
6+
7+
An `OpenIndexRequest` requires an `index` argument:
8+
9+
["source","java",subs="attributes,callouts,macros"]
10+
--------------------------------------------------
11+
include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[open-index-request]
12+
--------------------------------------------------
13+
<1> The index to open
14+
15+
==== Optional arguments
16+
The following arguments can optionally be provided:
17+
18+
["source","java",subs="attributes,callouts,macros"]
19+
--------------------------------------------------
20+
include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[open-index-request-timeout]
21+
--------------------------------------------------
22+
<1> Timeout to wait for the all the nodes to acknowledge the index is opened
23+
as a `TimeValue`
24+
<2> Timeout to wait for the all the nodes to acknowledge the index is opened
25+
as a `String`
26+
27+
["source","java",subs="attributes,callouts,macros"]
28+
--------------------------------------------------
29+
include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[open-index-request-masterTimeout]
30+
--------------------------------------------------
31+
<1> Timeout to connect to the master node as a `TimeValue`
32+
<2> Timeout to connect to the master node as a `String`
33+
34+
["source","java",subs="attributes,callouts,macros"]
35+
--------------------------------------------------
36+
include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[open-index-request-waitForActiveShards]
37+
--------------------------------------------------
38+
<1> The number of active shard copies to wait for before proceeding with the
39+
operation, as an `int`.
40+
<2> The number of active shard copies to wait for before proceeding with the
41+
operation, as an `ActiveShardCount`.
42+
43+
["source","java",subs="attributes,callouts,macros"]
44+
--------------------------------------------------
45+
include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[open-index-request-indicesOptions]
46+
--------------------------------------------------
47+
<1> Setting `IndicesOptions` controls how unavailable indices are resolved and
48+
how wildcard expressions are expanded
49+
50+
[[java-rest-high-open-index-sync]]
51+
==== Synchronous Execution
52+
53+
["source","java",subs="attributes,callouts,macros"]
54+
--------------------------------------------------
55+
include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[open-index-execute]
56+
--------------------------------------------------
57+
58+
[[java-rest-high-open-index-async]]
59+
==== Asynchronous Execution
60+
61+
["source","java",subs="attributes,callouts,macros"]
62+
--------------------------------------------------
63+
include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[open-index-execute-async]
64+
--------------------------------------------------
65+
<1> Called when the execution is successfully completed. The response is
66+
provided as an argument
67+
<2> Called in case of failure. The raised exception is provided as an argument
68+
69+
[[java-rest-high-open-index-response]]
70+
==== Open Index Response
71+
72+
The returned `OpenIndexResponse` allows to retrieve information about the
73+
executed operation as follows:
74+
75+
["source","java",subs="attributes,callouts,macros"]
76+
--------------------------------------------------
77+
include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[open-index-response]
78+
--------------------------------------------------
79+
<1> Indicates whether all of the nodes have acknowledged the request
80+
<2> Indicates whether the requisite number of shard copies were started for
81+
each shard in the index before timing out

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The Java High Level REST Client supports the following APIs:
66
Indices APIs::
77
* <<java-rest-high-create-index>>
88
* <<java-rest-high-delete-index>>
9+
* <<java-rest-high-open-index>>
910
* <<java-rest-high-close-index>>
1011

1112
Single document APIs::

0 commit comments

Comments
 (0)