From 68666a9bea2d3476dbd84b764325f12cb596e204 Mon Sep 17 00:00:00 2001 From: olcbean Date: Fri, 8 Dec 2017 15:01:42 +0100 Subject: [PATCH 1/8] remove redundant import-s minor formatting issues --- .../java/org/elasticsearch/client/IndicesClient.java | 12 +++++------- .../elasticsearch/client/RestHighLevelClient.java | 2 -- .../indices/close/TransportCloseIndexAction.java | 1 - .../action/admin/indices/open/OpenIndexResponse.java | 2 +- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java index 57dafbba50994..8c9c130fa4a38 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java @@ -51,7 +51,7 @@ public final class IndicesClient { */ public DeleteIndexResponse deleteIndex(DeleteIndexRequest deleteIndexRequest, Header... headers) throws IOException { return restHighLevelClient.performRequestAndParseEntity(deleteIndexRequest, Request::deleteIndex, DeleteIndexResponse::fromXContent, - Collections.emptySet(), headers); + Collections.emptySet(), headers); } /** @@ -60,10 +60,9 @@ public DeleteIndexResponse deleteIndex(DeleteIndexRequest deleteIndexRequest, He * See * Delete Index API on elastic.co */ - public void deleteIndexAsync(DeleteIndexRequest deleteIndexRequest, ActionListener listener, - Header... headers) { + public void deleteIndexAsync(DeleteIndexRequest deleteIndexRequest, ActionListener listener, Header... headers) { restHighLevelClient.performRequestAsyncAndParseEntity(deleteIndexRequest, Request::deleteIndex, DeleteIndexResponse::fromXContent, - listener, Collections.emptySet(), headers); + listener, Collections.emptySet(), headers); } /** @@ -83,10 +82,9 @@ public CreateIndexResponse createIndex(CreateIndexRequest createIndexRequest, He * See * Create Index API on elastic.co */ - public void createIndexAsync(CreateIndexRequest createIndexRequest, ActionListener listener, - Header... headers) { + public void createIndexAsync(CreateIndexRequest createIndexRequest, ActionListener listener, Header... headers) { restHighLevelClient.performRequestAsyncAndParseEntity(createIndexRequest, Request::createIndex, CreateIndexResponse::fromXContent, - listener, Collections.emptySet(), headers); + listener, Collections.emptySet(), headers); } /** diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java index ca244eee88c62..5f330256f6846 100755 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java @@ -26,8 +26,6 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; -import org.elasticsearch.action.admin.indices.open.OpenIndexResponse; import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.action.delete.DeleteRequest; diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/close/TransportCloseIndexAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/close/TransportCloseIndexAction.java index 244b8a24b9b67..362f54b74ab36 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/close/TransportCloseIndexAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/close/TransportCloseIndexAction.java @@ -22,7 +22,6 @@ import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.util.Supplier; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.open.OpenIndexResponse; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.DestructiveOperations; import org.elasticsearch.action.support.master.TransportMasterNodeAction; diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexResponse.java b/core/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexResponse.java index 95fef9fc65344..4e98c60265c76 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/open/OpenIndexResponse.java @@ -37,7 +37,7 @@ /** * A response for a open index action. */ -public class OpenIndexResponse extends AcknowledgedResponse implements ToXContentObject { +public class OpenIndexResponse extends AcknowledgedResponse implements ToXContentObject { private static final String SHARDS_ACKNOWLEDGED = "shards_acknowledged"; private static final ParseField SHARDS_ACKNOWLEDGED_PARSER = new ParseField(SHARDS_ACKNOWLEDGED); From ee8d666674dd4710d6460a08818e30dcf2a1b2c4 Mon Sep 17 00:00:00 2001 From: olcbean Date: Fri, 8 Dec 2017 19:13:51 +0100 Subject: [PATCH 2/8] Add Close Index API to the high level REST client --- .../elasticsearch/client/IndicesClient.java | 23 +++++++ .../org/elasticsearch/client/Request.java | 13 ++++ .../elasticsearch/client/IndicesClientIT.java | 50 +++++++++++++--- .../elasticsearch/client/RequestTests.java | 47 ++++++++------- .../indices/close/CloseIndexResponse.java | 24 +++++++- .../close/CloseIndexResponseTests.java | 60 +++++++++++++++++++ 6 files changed, 185 insertions(+), 32 deletions(-) create mode 100644 core/src/test/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponseTests.java diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java index 8c9c130fa4a38..4940267e85c22 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java @@ -21,6 +21,8 @@ import org.apache.http.Header; import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; +import org.elasticsearch.action.admin.indices.close.CloseIndexResponse; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; @@ -109,4 +111,25 @@ public void openIndexAsync(OpenIndexRequest openIndexRequest, ActionListener + * See + * Close Index API on elastic.co + */ + public CloseIndexResponse closeIndex(CloseIndexRequest closeIndexRequest, Header... headers) throws IOException { + return restHighLevelClient.performRequestAndParseEntity(closeIndexRequest, Request::closeIndex, CloseIndexResponse::fromXContent, + Collections.emptySet(), headers); + } + + /** + * Asynchronously closes an index using the Close Index API + *

+ * See + * Close Index API on elastic.co + */ + public void closeIndexAsync(CloseIndexRequest closeIndexRequest, ActionListener listener, Header... headers) { + restHighLevelClient.performRequestAsyncAndParseEntity(closeIndexRequest, Request::closeIndex, CloseIndexResponse::fromXContent, + listener, Collections.emptySet(), headers); + } } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/Request.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/Request.java index dd08179cf6297..99d2ecbda3a53 100755 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/Request.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/Request.java @@ -29,6 +29,7 @@ import org.apache.http.entity.ContentType; import org.apache.lucene.util.BytesRef; import org.elasticsearch.action.DocWriteRequest; +import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; @@ -152,6 +153,18 @@ static Request openIndex(OpenIndexRequest openIndexRequest) { return new Request(HttpPost.METHOD_NAME, endpoint, parameters.getParams(), null); } + static Request closeIndex(CloseIndexRequest closeIndexRequest) { + String endpoint = endpoint(closeIndexRequest.indices(), Strings.EMPTY_ARRAY, "_close"); + + Params parameters = Params.builder(); + + parameters.withTimeout(closeIndexRequest.timeout()); + parameters.withMasterTimeout(closeIndexRequest.masterNodeTimeout()); + parameters.withIndicesOptions(closeIndexRequest.indicesOptions()); + + return new Request(HttpPost.METHOD_NAME, endpoint, parameters.getParams(), null); + } + static Request createIndex(CreateIndexRequest createIndexRequest) throws IOException { String endpoint = endpoint(createIndexRequest.indices(), Strings.EMPTY_ARRAY, ""); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java index 5f356c4c29f5e..74aa483c22c5c 100755 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java @@ -21,6 +21,8 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.admin.indices.alias.Alias; +import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; +import org.elasticsearch.action.admin.indices.close.CloseIndexResponse; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; @@ -28,21 +30,19 @@ import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; import org.elasticsearch.action.admin.indices.open.OpenIndexResponse; import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.rest.RestStatus; - -import java.io.IOException; -import java.util.Locale; - -import static org.hamcrest.Matchers.equalTo; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; +import org.elasticsearch.rest.RestStatus; +import java.io.IOException; +import java.util.Locale; import java.util.Map; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS; +import static org.hamcrest.Matchers.equalTo; public class IndicesClientIT extends ESRestHighLevelClientTestCase { @@ -136,7 +136,7 @@ public void testDeleteIndex() throws IOException { } public void testOpenExistingIndex() throws IOException { - String[] indices = randomIndices(1, 5); + String[] indices = randomIndicesNames(1, 5); for (String index : indices) { createIndex(index); closeIndex(index); @@ -157,7 +157,7 @@ public void testOpenExistingIndex() throws IOException { } public void testOpenNonExistentIndex() throws IOException { - String[] nonExistentIndices = randomIndices(1, 5); + String[] nonExistentIndices = randomIndicesNames(1, 5); for (String nonExistentIndex : nonExistentIndices) { assertFalse(indexExists(nonExistentIndex)); } @@ -180,7 +180,39 @@ public void testOpenNonExistentIndex() throws IOException { assertEquals(RestStatus.NOT_FOUND, strictException.status()); } - private static String[] randomIndices(int minIndicesNum, int maxIndicesNum) { + public void testCloseExistingIndex() throws IOException { + String[] indices = randomIndicesNames(1, 5); + for (String index : indices) { + createIndex(index); + Response response = client().performRequest("GET", index + "/_search"); + assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus())); + } + + CloseIndexRequest closeIndexRequest = new CloseIndexRequest(indices); + CloseIndexResponse closeIndexResponse = execute(closeIndexRequest, highLevelClient().indices()::closeIndex, + highLevelClient().indices()::closeIndexAsync); + assertTrue(closeIndexResponse.isAcknowledged()); + + for (String index : indices) { + ResponseException exception = expectThrows(ResponseException.class, () -> client().performRequest("GET", index + "/_search")); + assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus())); + assertThat(exception.getMessage().contains(index), equalTo(true)); + } + } + + public void testCloseNonExistentIndex() throws IOException { + String[] nonExistentIndices = randomIndicesNames(1, 5); + for (String nonExistentIndex : nonExistentIndices) { + assertFalse(indexExists(nonExistentIndex)); + } + + CloseIndexRequest closeIndexRequest = new CloseIndexRequest(nonExistentIndices); + ElasticsearchException exception = expectThrows(ElasticsearchException.class, + () -> execute(closeIndexRequest, highLevelClient().indices()::closeIndex, highLevelClient().indices()::closeIndexAsync)); + assertEquals(RestStatus.NOT_FOUND, exception.status()); + } + + static String[] randomIndicesNames(int minIndicesNum, int maxIndicesNum) { int numIndices = randomIntBetween(minIndicesNum, maxIndicesNum); String[] indices = new String[numIndices]; for (int i = 0; i < numIndices; i++) { diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestTests.java index 7d63ed1ed4033..1388b2d35af01 100755 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestTests.java @@ -25,6 +25,7 @@ import org.apache.http.entity.StringEntity; import org.apache.http.util.EntityUtils; import org.elasticsearch.action.DocWriteRequest; +import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; @@ -270,17 +271,10 @@ public void testCreateIndex() throws IOException { } public void testDeleteIndex() { - DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(); - - int numIndices = randomIntBetween(0, 5); - String[] indices = new String[numIndices]; - for (int i = 0; i < numIndices; i++) { - indices[i] = "index-" + randomAlphaOfLengthBetween(2, 5); - } - deleteIndexRequest.indices(indices); + String[] indices = IndicesClientIT.randomIndicesNames(0, 5); + DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indices); Map expectedParams = new HashMap<>(); - setRandomTimeout(deleteIndexRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams); setRandomMasterTimeout(deleteIndexRequest, expectedParams); @@ -294,12 +288,8 @@ public void testDeleteIndex() { } public void testOpenIndex() { - OpenIndexRequest openIndexRequest = new OpenIndexRequest(); - int numIndices = randomIntBetween(1, 5); - String[] indices = new String[numIndices]; - for (int i = 0; i < numIndices; i++) { - indices[i] = "index-" + randomAlphaOfLengthBetween(2, 5); - } + String[] indices = IndicesClientIT.randomIndicesNames(1, 5); + OpenIndexRequest openIndexRequest = new OpenIndexRequest(indices); openIndexRequest.indices(indices); Map expectedParams = new HashMap<>(); @@ -316,6 +306,23 @@ public void testOpenIndex() { assertThat(request.getEntity(), nullValue()); } + public void testCloseIndex() { + String[] indices = IndicesClientIT.randomIndicesNames(1, 5); + CloseIndexRequest closeIndexRequest = new CloseIndexRequest(indices); + + Map expectedParams = new HashMap<>(); + setRandomTimeout(closeIndexRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams); + setRandomMasterTimeout(closeIndexRequest, expectedParams); + setRandomIndicesOptions(closeIndexRequest::indicesOptions, closeIndexRequest::indicesOptions, expectedParams); + + Request request = Request.closeIndex(closeIndexRequest); + StringJoiner endpoint = new StringJoiner("/", "/", "").add(String.join(",", indices)).add("_close"); + assertThat(endpoint.toString(), equalTo(request.getEndpoint())); + assertThat(expectedParams, equalTo(request.getParameters())); + assertThat(request.getMethod(), equalTo("POST")); + assertThat(request.getEntity(), nullValue()); + } + public void testIndex() throws IOException { String index = randomAlphaOfLengthBetween(3, 10); String type = randomAlphaOfLengthBetween(3, 10); @@ -693,13 +700,9 @@ public void testBulkWithDifferentContentTypes() throws IOException { } public void testSearch() throws Exception { - SearchRequest searchRequest = new SearchRequest(); - int numIndices = randomIntBetween(0, 5); - String[] indices = new String[numIndices]; - for (int i = 0; i < numIndices; i++) { - indices[i] = "index-" + randomAlphaOfLengthBetween(2, 5); - } - searchRequest.indices(indices); + String[] indices = IndicesClientIT.randomIndicesNames(0, 5); + SearchRequest searchRequest = new SearchRequest(indices); + int numTypes = randomIntBetween(0, 5); String[] types = new String[numTypes]; for (int i = 0; i < numTypes; i++) { diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponse.java b/core/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponse.java index b85962c0f55ed..4607586d9fa91 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponse.java @@ -22,13 +22,23 @@ import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.ToXContentObject; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; /** * A response for a close index action. */ -public class CloseIndexResponse extends AcknowledgedResponse { +public class CloseIndexResponse extends AcknowledgedResponse implements ToXContentObject { + private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("close_index", true, + args -> new CloseIndexResponse((boolean) args[0])); + + static { + declareAcknowledgedField(PARSER); + } CloseIndexResponse() { } @@ -48,4 +58,16 @@ public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); writeAcknowledged(out); } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + addAcknowledgedField(builder); + builder.endObject(); + return builder; + } + + public static CloseIndexResponse fromXContent(XContentParser parser) throws IOException { + return PARSER.apply(parser, null); + } } diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponseTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponseTests.java new file mode 100644 index 0000000000000..e616e0383118d --- /dev/null +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponseTests.java @@ -0,0 +1,60 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.action.admin.indices.close; + +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.test.ESTestCase; + +import java.io.IOException; + +import static org.elasticsearch.test.XContentTestUtils.insertRandomFields; +import static org.hamcrest.CoreMatchers.equalTo; + +public class CloseIndexResponseTests extends ESTestCase { + + public void testFromToXContent() throws IOException { + final CloseIndexResponse closeIndexResponse = createTestItem(); + + boolean humanReadable = randomBoolean(); + final XContentType xContentType = randomFrom(XContentType.values()); + BytesReference originalBytes = toShuffledXContent(closeIndexResponse, xContentType, ToXContent.EMPTY_PARAMS, humanReadable); + BytesReference mutated; + if (randomBoolean()) { + mutated = insertRandomFields(xContentType, originalBytes, null, random()); + } else { + mutated = originalBytes; + } + + CloseIndexResponse parsedCloseIndexResponse; + try (XContentParser parser = createParser(xContentType.xContent(), mutated)) { + parsedCloseIndexResponse = CloseIndexResponse.fromXContent(parser); + assertNull(parser.nextToken()); + } + assertThat(parsedCloseIndexResponse.isAcknowledged(), equalTo(closeIndexResponse.isAcknowledged())); + } + + private static CloseIndexResponse createTestItem() { + boolean acknowledged = randomBoolean(); + return new CloseIndexResponse(acknowledged); + } +} From 1b86d8053bceaf731e81576b13efb81168d03357 Mon Sep 17 00:00:00 2001 From: olcbean Date: Sun, 10 Dec 2017 20:07:34 +0100 Subject: [PATCH 3/8] tests clean up : requests to multiple indices done from UT instead of IT --- .../elasticsearch/client/IndicesClientIT.java | 74 +++++++------------ .../elasticsearch/client/RequestTests.java | 17 ++++- 2 files changed, 39 insertions(+), 52 deletions(-) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java index 74aa483c22c5c..361b60a5218cf 100755 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java @@ -38,7 +38,6 @@ import org.elasticsearch.rest.RestStatus; import java.io.IOException; -import java.util.Locale; import java.util.Map; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS; @@ -136,44 +135,38 @@ public void testDeleteIndex() throws IOException { } public void testOpenExistingIndex() throws IOException { - String[] indices = randomIndicesNames(1, 5); - for (String index : indices) { - createIndex(index); - closeIndex(index); - ResponseException exception = expectThrows(ResponseException.class, () -> client().performRequest("GET", index + "/_search")); - assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus())); - assertThat(exception.getMessage().contains(index), equalTo(true)); - } - - OpenIndexRequest openIndexRequest = new OpenIndexRequest(indices); + String index = "index"; + createIndex(index); + closeIndex(index); + ResponseException exception = expectThrows(ResponseException.class, () -> client().performRequest("GET", index + "/_search")); + assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus())); + assertThat(exception.getMessage().contains(index), equalTo(true)); + + OpenIndexRequest openIndexRequest = new OpenIndexRequest(index); OpenIndexResponse openIndexResponse = execute(openIndexRequest, highLevelClient().indices()::openIndex, highLevelClient().indices()::openIndexAsync); assertTrue(openIndexResponse.isAcknowledged()); - for (String index : indices) { - Response response = client().performRequest("GET", index + "/_search"); - assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus())); - } + Response response = client().performRequest("GET", index + "/_search"); + assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus())); } public void testOpenNonExistentIndex() throws IOException { - String[] nonExistentIndices = randomIndicesNames(1, 5); - for (String nonExistentIndex : nonExistentIndices) { - assertFalse(indexExists(nonExistentIndex)); - } + String nonExistentIndex = "non_existent_index"; + assertFalse(indexExists(nonExistentIndex)); - OpenIndexRequest openIndexRequest = new OpenIndexRequest(nonExistentIndices); + OpenIndexRequest openIndexRequest = new OpenIndexRequest(nonExistentIndex); ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> execute(openIndexRequest, highLevelClient().indices()::openIndex, highLevelClient().indices()::openIndexAsync)); assertEquals(RestStatus.NOT_FOUND, exception.status()); - OpenIndexRequest lenientOpenIndexRequest = new OpenIndexRequest(nonExistentIndices); + OpenIndexRequest lenientOpenIndexRequest = new OpenIndexRequest(nonExistentIndex); lenientOpenIndexRequest.indicesOptions(IndicesOptions.lenientExpandOpen()); OpenIndexResponse lenientOpenIndexResponse = execute(lenientOpenIndexRequest, highLevelClient().indices()::openIndex, highLevelClient().indices()::openIndexAsync); assertThat(lenientOpenIndexResponse.isAcknowledged(), equalTo(true)); - OpenIndexRequest strictOpenIndexRequest = new OpenIndexRequest(nonExistentIndices); + OpenIndexRequest strictOpenIndexRequest = new OpenIndexRequest(nonExistentIndex); strictOpenIndexRequest.indicesOptions(IndicesOptions.strictExpandOpen()); ElasticsearchException strictException = expectThrows(ElasticsearchException.class, () -> execute(openIndexRequest, highLevelClient().indices()::openIndex, highLevelClient().indices()::openIndexAsync)); @@ -181,46 +174,31 @@ public void testOpenNonExistentIndex() throws IOException { } public void testCloseExistingIndex() throws IOException { - String[] indices = randomIndicesNames(1, 5); - for (String index : indices) { - createIndex(index); - Response response = client().performRequest("GET", index + "/_search"); - assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus())); - } + String index = "index"; + createIndex(index); + Response response = client().performRequest("GET", index + "/_search"); + assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus())); - CloseIndexRequest closeIndexRequest = new CloseIndexRequest(indices); + CloseIndexRequest closeIndexRequest = new CloseIndexRequest(index); CloseIndexResponse closeIndexResponse = execute(closeIndexRequest, highLevelClient().indices()::closeIndex, highLevelClient().indices()::closeIndexAsync); assertTrue(closeIndexResponse.isAcknowledged()); - for (String index : indices) { - ResponseException exception = expectThrows(ResponseException.class, () -> client().performRequest("GET", index + "/_search")); - assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus())); - assertThat(exception.getMessage().contains(index), equalTo(true)); - } + ResponseException exception = expectThrows(ResponseException.class, () -> client().performRequest("GET", index + "/_search")); + assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus())); + assertThat(exception.getMessage().contains(index), equalTo(true)); } public void testCloseNonExistentIndex() throws IOException { - String[] nonExistentIndices = randomIndicesNames(1, 5); - for (String nonExistentIndex : nonExistentIndices) { - assertFalse(indexExists(nonExistentIndex)); - } + String nonExistentIndex = "non_existent_index"; + assertFalse(indexExists(nonExistentIndex)); - CloseIndexRequest closeIndexRequest = new CloseIndexRequest(nonExistentIndices); + CloseIndexRequest closeIndexRequest = new CloseIndexRequest(nonExistentIndex); ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> execute(closeIndexRequest, highLevelClient().indices()::closeIndex, highLevelClient().indices()::closeIndexAsync)); assertEquals(RestStatus.NOT_FOUND, exception.status()); } - static String[] randomIndicesNames(int minIndicesNum, int maxIndicesNum) { - int numIndices = randomIntBetween(minIndicesNum, maxIndicesNum); - String[] indices = new String[numIndices]; - for (int i = 0; i < numIndices; i++) { - indices[i] = "index-" + randomAlphaOfLengthBetween(2, 5).toLowerCase(Locale.ROOT); - } - return indices; - } - private static void createIndex(String index) throws IOException { Response response = client().performRequest("PUT", index); assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus())); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestTests.java index 1388b2d35af01..e252311242e67 100755 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestTests.java @@ -271,7 +271,7 @@ public void testCreateIndex() throws IOException { } public void testDeleteIndex() { - String[] indices = IndicesClientIT.randomIndicesNames(0, 5); + String[] indices = randomIndicesNames(0, 5); DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indices); Map expectedParams = new HashMap<>(); @@ -288,7 +288,7 @@ public void testDeleteIndex() { } public void testOpenIndex() { - String[] indices = IndicesClientIT.randomIndicesNames(1, 5); + String[] indices = randomIndicesNames(1, 5); OpenIndexRequest openIndexRequest = new OpenIndexRequest(indices); openIndexRequest.indices(indices); @@ -307,7 +307,7 @@ public void testOpenIndex() { } public void testCloseIndex() { - String[] indices = IndicesClientIT.randomIndicesNames(1, 5); + String[] indices = randomIndicesNames(1, 5); CloseIndexRequest closeIndexRequest = new CloseIndexRequest(indices); Map expectedParams = new HashMap<>(); @@ -700,7 +700,7 @@ public void testBulkWithDifferentContentTypes() throws IOException { } public void testSearch() throws Exception { - String[] indices = IndicesClientIT.randomIndicesNames(0, 5); + String[] indices = randomIndicesNames(0, 5); SearchRequest searchRequest = new SearchRequest(indices); int numTypes = randomIntBetween(0, 5); @@ -1072,4 +1072,13 @@ private static String randomFields(String[] fields) { } return excludesParam.toString(); } + + private static String[] randomIndicesNames(int minIndicesNum, int maxIndicesNum) { + int numIndices = randomIntBetween(minIndicesNum, maxIndicesNum); + String[] indices = new String[numIndices]; + for (int i = 0; i < numIndices; i++) { + indices[i] = "index-" + randomAlphaOfLengthBetween(2, 5).toLowerCase(Locale.ROOT); + } + return indices; + } } From 4760c5d960b2f766c03c952903c9086a6140f9c2 Mon Sep 17 00:00:00 2001 From: olcbean Date: Mon, 11 Dec 2017 18:07:22 +0100 Subject: [PATCH 4/8] adding docs for close index --- .../IndicesClientDocumentationIT.java | 66 +++++++++++++++++++ .../high-level/apis/close_index.asciidoc | 63 ++++++++++++++++++ .../high-level/apis/createindex.asciidoc | 2 +- docs/java-rest/high-level/apis/index.asciidoc | 11 ++++ .../high-level/supported-apis.asciidoc | 1 + 5 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 docs/java-rest/high-level/apis/close_index.asciidoc diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java index 372cc17d137bc..2460a2aa1f662 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java @@ -22,6 +22,8 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.alias.Alias; +import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; +import org.elasticsearch.action.admin.indices.close.CloseIndexResponse; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; @@ -190,4 +192,68 @@ public void onFailure(Exception e) { // end::create-index-execute-async } } + + public void closeIndex() throws IOException { + RestHighLevelClient client = highLevelClient(); + + { + CreateIndexResponse createIndexResponse = client.indices().createIndex(new CreateIndexRequest("index")); + assertTrue(createIndexResponse.isAcknowledged()); + } + + { + // tag::close-index-request + CloseIndexRequest request = new CloseIndexRequest("index"); // <1> + // end::close-index-request + + // tag::close-index-request-timeout + request.timeout(TimeValue.timeValueMinutes(2)); // <1> + request.timeout("2m"); // <2> + // end::close-index-request-timeout + // tag::close-index-request-masterTimeout + request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> + request.masterNodeTimeout("1m"); // <2> + // end::close-index-request-masterTimeout + + // tag::close-index-request-indicesOptions + request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1> + // end::close-index-request-indicesOptions + + // tag::close-index-execute + CloseIndexResponse closeIndexResponse = client.indices().closeIndex(request); + // end::close-index-execute + + // tag::close-index-response + boolean acknowledged = closeIndexResponse.isAcknowledged(); // <1> + // end::close-index-response + assertTrue(acknowledged); + + // tag::close-index-execute-async + client.indices().closeIndexAsync(request, new ActionListener() { + @Override + public void onResponse(CloseIndexResponse deleteIndexResponse) { + // <1> + } + + @Override + public void onFailure(Exception e) { + // <2> + } + }); + // end::close-index-execute-async + } + + { + // tag::close-index-notfound + try { + CloseIndexRequest request = new CloseIndexRequest("does_not_exist"); + client.indices().closeIndex(request); + } catch (ElasticsearchException exception) { + if (exception.status() == RestStatus.BAD_REQUEST) { + // <1> + } + } + // end::close-index-notfound + } + } } diff --git a/docs/java-rest/high-level/apis/close_index.asciidoc b/docs/java-rest/high-level/apis/close_index.asciidoc new file mode 100644 index 0000000000000..9ed0d63173946 --- /dev/null +++ b/docs/java-rest/high-level/apis/close_index.asciidoc @@ -0,0 +1,63 @@ +[[java-rest-high-close-index]] +=== Close Index API + +[[java-rest-high-close-index-request]] +==== Close Index Request + +A `CloseIndexRequest` requires an `index` argument: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[close-index-request] +-------------------------------------------------- +<1> The index to close + +==== Optional arguments +The following arguments can optionally be provided: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[close-index-request-timeout] +-------------------------------------------------- +<1> Timeout to wait for the all the nodes to acknowledge the index is closed +as a `TimeValue` +<2> Timeout to wait for the all the nodes to acknowledge the index is closed +as a `String` + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[close-index-request-masterTimeout] +-------------------------------------------------- +<1> Timeout to connect to the master node as a `TimeValue` +<2> Timeout to connect to the master node as a `String` + +[[java-rest-high-close-index-sync]] +==== Synchronous Execution + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[close-index-execute] +-------------------------------------------------- + +[[java-rest-high-close-index-async]] +==== Asynchronous Execution + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[close-index-execute-async] +-------------------------------------------------- +<1> Called when the execution is successfully completed. The response is +provided as an argument +<2> Called in case of failure. The raised exception is provided as an argument + +[[java-rest-high-close-index-response]] +==== Close Index Response + +The returned `CloseIndexResponse` allows to retrieve information about the +executed operation as follows: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[close-index-response] +-------------------------------------------------- +<1> Indicates whether all of the nodes have acknowledged the request diff --git a/docs/java-rest/high-level/apis/createindex.asciidoc b/docs/java-rest/high-level/apis/createindex.asciidoc index ebd9158e19387..a3cf373d7e060 100644 --- a/docs/java-rest/high-level/apis/createindex.asciidoc +++ b/docs/java-rest/high-level/apis/createindex.asciidoc @@ -48,7 +48,7 @@ The following arguments can optionally be provided: include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-request-timeout] -------------------------------------------------- <1> Timeout to wait for the all the nodes to acknowledge the index creation as a `TimeValue` -<2> Timeout to wait for the all the nodes to acknowledge the index creatiom as a `String` +<2> Timeout to wait for the all the nodes to acknowledge the index creation as a `String` ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- diff --git a/docs/java-rest/high-level/apis/index.asciidoc b/docs/java-rest/high-level/apis/index.asciidoc index 2312f28372060..05252493d9201 100644 --- a/docs/java-rest/high-level/apis/index.asciidoc +++ b/docs/java-rest/high-level/apis/index.asciidoc @@ -1,10 +1,21 @@ include::createindex.asciidoc[] + include::deleteindex.asciidoc[] + +include::close_index.asciidoc[] + include::_index.asciidoc[] + include::get.asciidoc[] + include::delete.asciidoc[] + include::update.asciidoc[] + include::bulk.asciidoc[] + include::search.asciidoc[] + include::scroll.asciidoc[] + include::main.asciidoc[] diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index 7a6b55619f77a..a2d35932dab98 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.asciidoc @@ -6,6 +6,7 @@ The Java High Level REST Client supports the following APIs: Indices APIs:: * <> * <> +* <> Single document APIs:: * <> From 4c2626c56b0362b68ca208b72826931f99994273 Mon Sep 17 00:00:00 2001 From: olcbean Date: Mon, 11 Dec 2017 21:05:11 +0100 Subject: [PATCH 5/8] add docs for open index --- .../IndicesClientDocumentationIT.java | 68 +++++++++++++++- .../high-level/apis/close_index.asciidoc | 7 ++ docs/java-rest/high-level/apis/index.asciidoc | 2 + .../high-level/apis/open_index.asciidoc | 81 +++++++++++++++++++ .../high-level/supported-apis.asciidoc | 1 + 5 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 docs/java-rest/high-level/apis/open_index.asciidoc diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java index 2460a2aa1f662..acda5f3d405e1 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java @@ -28,6 +28,8 @@ import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; +import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; +import org.elasticsearch.action.admin.indices.open.OpenIndexResponse; import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.ESRestHighLevelClientTestCase; @@ -193,6 +195,70 @@ public void onFailure(Exception e) { } } + public void openIndex() throws IOException { + RestHighLevelClient client = highLevelClient(); + + { + CreateIndexResponse createIndexResponse = client.indices().createIndex(new CreateIndexRequest("index")); + assertTrue(createIndexResponse.isAcknowledged()); + } + + { + // tag::open-index-request + OpenIndexRequest request = new OpenIndexRequest("index"); // <1> + // end::open-index-request + + // tag::open-index-request-timeout + request.timeout(TimeValue.timeValueMinutes(2)); // <1> + request.timeout("2m"); // <2> + // end::open-index-request-timeout + // tag::open-index-request-masterTimeout + request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> + request.masterNodeTimeout("1m"); // <2> + // end::open-index-request-masterTimeout + + // tag::open-index-request-indicesOptions + request.indicesOptions(IndicesOptions.strictExpandOpen()); // <1> + // end::open-index-request-indicesOptions + + // tag::open-index-execute + OpenIndexResponse openIndexResponse = client.indices().openIndex(request); + // end::open-index-execute + + // tag::open-index-response + boolean acknowledged = openIndexResponse.isAcknowledged(); // <1> + // end::open-index-response + assertTrue(acknowledged); + + // tag::open-index-execute-async + client.indices().openIndexAsync(request, new ActionListener() { + @Override + public void onResponse(OpenIndexResponse openIndexResponse) { + // <1> + } + + @Override + public void onFailure(Exception e) { + // <2> + } + }); + // end::open-index-execute-async + } + + { + // tag::open-index-notfound + try { + OpenIndexRequest request = new OpenIndexRequest("does_not_exist"); + client.indices().openIndex(request); + } catch (ElasticsearchException exception) { + if (exception.status() == RestStatus.BAD_REQUEST) { + // <1> + } + } + // end::open-index-notfound + } + } + public void closeIndex() throws IOException { RestHighLevelClient client = highLevelClient(); @@ -231,7 +297,7 @@ public void closeIndex() throws IOException { // tag::close-index-execute-async client.indices().closeIndexAsync(request, new ActionListener() { @Override - public void onResponse(CloseIndexResponse deleteIndexResponse) { + public void onResponse(CloseIndexResponse closeIndexResponse) { // <1> } diff --git a/docs/java-rest/high-level/apis/close_index.asciidoc b/docs/java-rest/high-level/apis/close_index.asciidoc index 9ed0d63173946..a4d0f6383532e 100644 --- a/docs/java-rest/high-level/apis/close_index.asciidoc +++ b/docs/java-rest/high-level/apis/close_index.asciidoc @@ -31,6 +31,13 @@ include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[close-index-reques <1> Timeout to connect to the master node as a `TimeValue` <2> Timeout to connect to the master node as a `String` +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[close-index-request-indicesOptions] +-------------------------------------------------- +<1> Setting `IndicesOptions` controls how unavailable indices are resolved and +how wildcard expressions are expanded + [[java-rest-high-close-index-sync]] ==== Synchronous Execution diff --git a/docs/java-rest/high-level/apis/index.asciidoc b/docs/java-rest/high-level/apis/index.asciidoc index 05252493d9201..f6da998a8476f 100644 --- a/docs/java-rest/high-level/apis/index.asciidoc +++ b/docs/java-rest/high-level/apis/index.asciidoc @@ -2,6 +2,8 @@ include::createindex.asciidoc[] include::deleteindex.asciidoc[] +include::open_index.asciidoc[] + include::close_index.asciidoc[] include::_index.asciidoc[] diff --git a/docs/java-rest/high-level/apis/open_index.asciidoc b/docs/java-rest/high-level/apis/open_index.asciidoc new file mode 100644 index 0000000000000..71b1e42a627a0 --- /dev/null +++ b/docs/java-rest/high-level/apis/open_index.asciidoc @@ -0,0 +1,81 @@ +[[java-rest-high-open-index]] +=== Open Index API + +[[java-rest-high-open-index-request]] +==== Open Index Request + +An `OpenIndexRequest` requires an `index` argument: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[open-index-request] +-------------------------------------------------- +<1> The index to open + +==== Optional arguments +The following arguments can optionally be provided: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[open-index-request-timeout] +-------------------------------------------------- +<1> Timeout to wait for the all the nodes to acknowledge the index is opened +as a `TimeValue` +<2> Timeout to wait for the all the nodes to acknowledge the index is opened +as a `String` + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[open-index-request-masterTimeout] +-------------------------------------------------- +<1> Timeout to connect to the master node as a `TimeValue` +<2> Timeout to connect to the master node as a `String` + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[open-index-request-waitForActiveShards] +-------------------------------------------------- +<1> The number of active shard copies to wait for before proceeding with the +operation, as an `int`. +<2> The number of active shard copies to wait for before proceeding with the +operation, as an `ActiveShardCount`. + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[open-index-request-indicesOptions] +-------------------------------------------------- +<1> Setting `IndicesOptions` controls how unavailable indices are resolved and +how wildcard expressions are expanded + +[[java-rest-high-open-index-sync]] +==== Synchronous Execution + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[open-index-execute] +-------------------------------------------------- + +[[java-rest-high-open-index-async]] +==== Asynchronous Execution + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[open-index-execute-async] +-------------------------------------------------- +<1> Called when the execution is successfully completed. The response is +provided as an argument +<2> Called in case of failure. The raised exception is provided as an argument + +[[java-rest-high-open-index-response]] +==== Open Index Response + +The returned `OpenIndexResponse` allows to retrieve information about the +executed operation as follows: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[open-index-response] +-------------------------------------------------- +<1> Indicates whether all of the nodes have acknowledged the request +<2> Indicates whether the requisite number of shard copies were started for +each shard in the index before timing out diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index a2d35932dab98..fa71b62d64e70 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.asciidoc @@ -6,6 +6,7 @@ The Java High Level REST Client supports the following APIs: Indices APIs:: * <> * <> +* <> * <> Single document APIs:: From e2767bec2aa90b619ba1a3813a5a076e8583dff2 Mon Sep 17 00:00:00 2001 From: olcbean Date: Tue, 12 Dec 2017 11:38:27 +0100 Subject: [PATCH 6/8] fix IndicesClientDocumentionIT for open index and acknowledged shards --- .../client/documentation/IndicesClientDocumentationIT.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java index acda5f3d405e1..bf230356db336 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java @@ -216,6 +216,11 @@ public void openIndex() throws IOException { request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> request.masterNodeTimeout("1m"); // <2> // end::open-index-request-masterTimeout + // tag::open-index-request-waitForActiveShards + request.waitForActiveShards(2); // <1> + request.waitForActiveShards(ActiveShardCount.DEFAULT); // <2> + // end::open-index-request-waitForActiveShards + // tag::open-index-request-indicesOptions request.indicesOptions(IndicesOptions.strictExpandOpen()); // <1> @@ -227,8 +232,10 @@ public void openIndex() throws IOException { // tag::open-index-response boolean acknowledged = openIndexResponse.isAcknowledged(); // <1> + boolean shardsAcked = openIndexResponse.isShardsAcknowledged(); // <2> // end::open-index-response assertTrue(acknowledged); + assertTrue(shardsAcked); // tag::open-index-execute-async client.indices().openIndexAsync(request, new ActionListener() { From 623da6ac368ae4a70065a4dbf242d0f5a1252674 Mon Sep 17 00:00:00 2001 From: javanna Date: Tue, 16 Jan 2018 16:17:45 +0100 Subject: [PATCH 7/8] amended wait for active shards explanation --- docs/java-rest/high-level/apis/createindex.asciidoc | 6 ++++-- docs/java-rest/high-level/apis/open_index.asciidoc | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/java-rest/high-level/apis/createindex.asciidoc b/docs/java-rest/high-level/apis/createindex.asciidoc index a3cf373d7e060..bfc7794c8f9a0 100644 --- a/docs/java-rest/high-level/apis/createindex.asciidoc +++ b/docs/java-rest/high-level/apis/createindex.asciidoc @@ -61,8 +61,10 @@ include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-reque -------------------------------------------------- include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[create-index-request-waitForActiveShards] -------------------------------------------------- -<1> The number of active shard copies to wait for before proceeding with the operation, as an `int`. -<2> The number of active shard copies to wait for before proceeding with the operation, as an `ActiveShardCount`. +<1> The number of active shard copies to wait for before the create index API returns a +response, as an `int`. +<2> The number of active shard copies to wait for before the create index API returns a +response, as an `ActiveShardCount`. [[java-rest-high-create-index-sync]] ==== Synchronous Execution diff --git a/docs/java-rest/high-level/apis/open_index.asciidoc b/docs/java-rest/high-level/apis/open_index.asciidoc index 71b1e42a627a0..a30e62123a814 100644 --- a/docs/java-rest/high-level/apis/open_index.asciidoc +++ b/docs/java-rest/high-level/apis/open_index.asciidoc @@ -35,10 +35,10 @@ include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[open-index-request -------------------------------------------------- include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[open-index-request-waitForActiveShards] -------------------------------------------------- -<1> The number of active shard copies to wait for before proceeding with the -operation, as an `int`. -<2> The number of active shard copies to wait for before proceeding with the -operation, as an `ActiveShardCount`. +<1> The number of active shard copies to wait for before the open index API +returns a response, as an `int`. +<2> The number of active shard copies to wait for before the open index API +returns a response, as an `ActiveShardCount`. ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- From 015811ce98a8b930ce36eb14aa0591ae2b46e69d Mon Sep 17 00:00:00 2001 From: javanna Date: Tue, 16 Jan 2018 16:24:30 +0100 Subject: [PATCH 8/8] move CloseIndexResponseTests to server module (core has been renamed to server) --- .../action/admin/indices/close/CloseIndexResponseTests.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {core => server}/src/test/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponseTests.java (100%) diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponseTests.java similarity index 100% rename from core/src/test/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponseTests.java rename to server/src/test/java/org/elasticsearch/action/admin/indices/close/CloseIndexResponseTests.java