From a3a2f22ab7d8a77344c1978cb40e6c62a7334b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Tue, 14 Nov 2017 11:17:46 +0100 Subject: [PATCH 01/25] #27205: Indices exist. --- .../elasticsearch/client/IndicesClient.java | 19 ++++++++++++++++--- .../elasticsearch/client/IndicesClientIT.java | 15 +++++++++++++++ 2 files changed, 31 insertions(+), 3 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 2cc1d4849d5a8..863401ad64f35 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 @@ -23,9 +23,12 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; +import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; +import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; import java.io.IOException; -import java.util.Collections; + +import static java.util.Collections.emptySet; /** * A wrapper for the {@link RestHighLevelClient} that provides methods for accessing the Indices API. @@ -47,7 +50,7 @@ public IndicesClient(RestHighLevelClient restHighLevelClient) { */ public DeleteIndexResponse deleteIndex(DeleteIndexRequest deleteIndexRequest, Header... headers) throws IOException { return restHighLevelClient.performRequestAndParseEntity(deleteIndexRequest, Request::deleteIndex, DeleteIndexResponse::fromXContent, - Collections.emptySet(), headers); + emptySet(), headers); } /** @@ -58,6 +61,16 @@ public DeleteIndexResponse deleteIndex(DeleteIndexRequest deleteIndexRequest, He */ public void deleteIndexAsync(DeleteIndexRequest deleteIndexRequest, ActionListener listener, Header... headers) { restHighLevelClient.performRequestAsyncAndParseEntity(deleteIndexRequest, Request::deleteIndex, DeleteIndexResponse::fromXContent, - listener, Collections.emptySet(), headers); + listener, emptySet(), headers); + } + + public IndicesExistsResponse exists(IndicesExistsRequest indicesExistsRequest, Header... headers) throws IOException { + return restHighLevelClient.performRequestAsyncAndParseEntity( + indicesExistsRequest, + Request::indicesExist, + IndicesExistsResponse::fromXContent, + emptySet(), + headers + ); } } 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 4045e565288e5..b0a2bb32c459d 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 @@ -22,12 +22,27 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; +import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; +import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; import org.elasticsearch.rest.RestStatus; import java.io.IOException; public class IndicesClientIT extends ESRestHighLevelClientTestCase { + public void testIndexExists_IndexPresent() throws IOException { + // Delete index if exists + String indexName = "testIndexExists_IndexPresent"; + createIndex(indexName); + + IndicesExistsRequest request = new IndicesExistsRequest(indexName); + IndicesExistsResponse response = execute( + request, + highLevelClient().indices()::indexExists, + + ) + } + public void testDeleteIndex() throws IOException { { // Delete index if exists From 5b6bd873c605d0e1c4c74e0ca37ff000de6ee5d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Tue, 14 Nov 2017 12:01:04 +0100 Subject: [PATCH 02/25] #27205: Indices exist. First tests. --- .../elasticsearch/client/IndicesClient.java | 13 ++++++++++++- .../org/elasticsearch/client/Request.java | 8 +++++++- .../client/ESRestHighLevelClientTestCase.java | 2 +- .../elasticsearch/client/IndicesClientIT.java | 19 +++++++++++++++++-- .../exists/indices/IndicesExistsResponse.java | 14 +++++++++++++- 5 files changed, 50 insertions(+), 6 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 863401ad64f35..856fe34281b03 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 @@ -65,7 +65,7 @@ public void deleteIndexAsync(DeleteIndexRequest deleteIndexRequest, ActionListen } public IndicesExistsResponse exists(IndicesExistsRequest indicesExistsRequest, Header... headers) throws IOException { - return restHighLevelClient.performRequestAsyncAndParseEntity( + return restHighLevelClient.performRequestAndParseEntity( indicesExistsRequest, Request::indicesExist, IndicesExistsResponse::fromXContent, @@ -73,4 +73,15 @@ public IndicesExistsResponse exists(IndicesExistsRequest indicesExistsRequest, H headers ); } + + public void existsAsync(IndicesExistsRequest indicesExistsRequest, ActionListener listener, Header... headers) throws IOException { + restHighLevelClient.performRequestAsyncAndParseEntity( + indicesExistsRequest, + Request::indicesExist, + IndicesExistsResponse::fromXContent, + listener, + 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 e2a6dcac20b06..7a52abe35e292 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 @@ -28,8 +28,10 @@ import org.apache.http.entity.ByteArrayEntity; import org.apache.http.entity.ContentType; import org.apache.lucene.util.BytesRef; +import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.DocWriteRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; +import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.get.GetRequest; @@ -410,10 +412,14 @@ static String endpoint(String... parts) { * @return the {@link ContentType} */ @SuppressForbidden(reason = "Only allowed place to convert a XContentType to a ContentType") - public static ContentType createContentType(final XContentType xContentType) { + public static ContentType createContentType(final XContentType xContentType) { return ContentType.create(xContentType.mediaTypeWithoutParameters(), (Charset) null); } + static Request indicesExist(IndicesExistsRequest req) { + return null; + } + /** * Utility class to build request's parameters map and centralize all parameter names. */ diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java index aabe2c4d1e270..dfcca29ffd2b6 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java @@ -72,7 +72,7 @@ protected interface SyncMethod { @FunctionalInterface protected interface AsyncMethod { - void execute(Request request, ActionListener listener, Header... headers); + void execute(Request request, ActionListener listener, Header... headers) throws IOException; } private static class HighLevelClient extends RestHighLevelClient { 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 b0a2bb32c459d..4d85cf9021466 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,9 +38,24 @@ public void testIndexExists_IndexPresent() throws IOException { IndicesExistsRequest request = new IndicesExistsRequest(indexName); IndicesExistsResponse response = execute( request, - highLevelClient().indices()::indexExists, + highLevelClient().indices()::exists, + highLevelClient().indices()::existsAsync + ); + assertTrue(response.isExists()); + } + + public void testIndexExists_IndexNotPresent() throws IOException { + // Delete index if exists + String indexName = "non_existent_index"; + createIndex(indexName); - ) + IndicesExistsRequest request = new IndicesExistsRequest(indexName); + IndicesExistsResponse response = execute( + request, + highLevelClient().indices()::exists, + highLevelClient().indices()::existsAsync + ); + assertFalse(response.isExists()); } public void testDeleteIndex() throws IOException { diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsResponse.java b/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsResponse.java index 82d98285e1edf..b7b5ce33c2841 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsResponse.java @@ -22,10 +22,13 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.ToXContentObject; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; -public class IndicesExistsResponse extends ActionResponse { +public class IndicesExistsResponse extends ActionResponse implements ToXContentObject { private boolean exists; @@ -51,4 +54,13 @@ public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeBoolean(exists); } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + return null; + } + + public static IndicesExistsResponse fromXContent(XContentParser xContentParser) { + return null; + } } \ No newline at end of file From d05262f10d63aaca96c8e1063851741cc53d182c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Tue, 14 Nov 2017 15:56:59 +0100 Subject: [PATCH 03/25] HLRC: More tests. First functional version. --- .../elasticsearch/client/IndicesClient.java | 12 ++++++++---- .../org/elasticsearch/client/Request.java | 16 ++++++++++------ .../elasticsearch/client/IndicesClientIT.java | 19 ++++++++++++++++--- .../elasticsearch/client/RequestTests.java | 19 +++++++++++++++++++ 4 files changed, 53 insertions(+), 13 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 856fe34281b03..7da839bd23b48 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 @@ -65,20 +65,24 @@ public void deleteIndexAsync(DeleteIndexRequest deleteIndexRequest, ActionListen } public IndicesExistsResponse exists(IndicesExistsRequest indicesExistsRequest, Header... headers) throws IOException { - return restHighLevelClient.performRequestAndParseEntity( + return restHighLevelClient.performRequest( indicesExistsRequest, Request::indicesExist, - IndicesExistsResponse::fromXContent, + this::parseIndicesExistResp, emptySet(), headers ); } + private IndicesExistsResponse parseIndicesExistResp(Response response) { + return new IndicesExistsResponse(response.getStatusLine().getStatusCode() == 200); + } + public void existsAsync(IndicesExistsRequest indicesExistsRequest, ActionListener listener, Header... headers) throws IOException { - restHighLevelClient.performRequestAsyncAndParseEntity( + restHighLevelClient.performRequestAsync( indicesExistsRequest, Request::indicesExist, - IndicesExistsResponse::fromXContent, + this::parseIndicesExistResp, listener, 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 7a52abe35e292..e3eb74a8493c2 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 @@ -69,6 +69,8 @@ import java.util.Objects; import java.util.StringJoiner; +import static java.util.Collections.emptyMap; + public final class Request { static final XContentType REQUEST_BODY_CONTENT_TYPE = XContentType.JSON; @@ -138,7 +140,7 @@ static Request deleteIndex(DeleteIndexRequest deleteIndexRequest) { } static Request info() { - return new Request(HttpGet.METHOD_NAME, "/", Collections.emptyMap(), null); + return new Request(HttpGet.METHOD_NAME, "/", emptyMap(), null); } static Request bulk(BulkRequest bulkRequest) throws IOException { @@ -308,7 +310,7 @@ static Request index(IndexRequest indexRequest) { } static Request ping() { - return new Request(HttpHead.METHOD_NAME, "/", Collections.emptyMap(), null); + return new Request(HttpHead.METHOD_NAME, "/", emptyMap(), null); } static Request update(UpdateRequest updateRequest) throws IOException { @@ -375,12 +377,12 @@ static Request search(SearchRequest searchRequest) throws IOException { static Request searchScroll(SearchScrollRequest searchScrollRequest) throws IOException { HttpEntity entity = createEntity(searchScrollRequest, REQUEST_BODY_CONTENT_TYPE); - return new Request("GET", "/_search/scroll", Collections.emptyMap(), entity); + return new Request("GET", "/_search/scroll", emptyMap(), entity); } static Request clearScroll(ClearScrollRequest clearScrollRequest) throws IOException { HttpEntity entity = createEntity(clearScrollRequest, REQUEST_BODY_CONTENT_TYPE); - return new Request("DELETE", "/_search/scroll", Collections.emptyMap(), entity); + return new Request("DELETE", "/_search/scroll", emptyMap(), entity); } private static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType) throws IOException { @@ -416,8 +418,10 @@ public static ContentType createContentType(final XC return ContentType.create(xContentType.mediaTypeWithoutParameters(), (Charset) null); } - static Request indicesExist(IndicesExistsRequest req) { - return null; + static Request indicesExist(IndicesExistsRequest request) { + String endpoint = endpoint(request.indices(), Strings.EMPTY_ARRAY, ""); + + return new Request(HttpHead.METHOD_NAME, endpoint, emptyMap(), null); } /** 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 4d85cf9021466..c30d80c71531e 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 @@ -32,7 +32,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase { public void testIndexExists_IndexPresent() throws IOException { // Delete index if exists - String indexName = "testIndexExists_IndexPresent"; + String indexName = "test_index_exists_index_present"; createIndex(indexName); IndicesExistsRequest request = new IndicesExistsRequest(indexName); @@ -45,9 +45,7 @@ public void testIndexExists_IndexPresent() throws IOException { } public void testIndexExists_IndexNotPresent() throws IOException { - // Delete index if exists String indexName = "non_existent_index"; - createIndex(indexName); IndicesExistsRequest request = new IndicesExistsRequest(indexName); IndicesExistsResponse response = execute( @@ -58,6 +56,21 @@ public void testIndexExists_IndexNotPresent() throws IOException { assertFalse(response.isExists()); } + public void testIndexExists_OneIndexPresent_OneIsnt() throws IOException { + String existingIndex = "test_index_exists_index_present"; + createIndex(existingIndex); + + String nonExistentIndex = "non_existent_index"; + + IndicesExistsRequest request = new IndicesExistsRequest(existingIndex, nonExistentIndex); + IndicesExistsResponse response = execute( + request, + highLevelClient().indices()::exists, + highLevelClient().indices()::existsAsync + ); + assertFalse(response.isExists()); + } + public void testDeleteIndex() throws IOException { { // Delete index if exists 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 3be250d513d21..7bc197a5ee395 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 @@ -26,6 +26,7 @@ import org.apache.http.util.EntityUtils; import org.elasticsearch.action.DocWriteRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; +import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.bulk.BulkShardRequest; import org.elasticsearch.action.delete.DeleteRequest; @@ -173,6 +174,24 @@ public void testExists() { getAndExistsTest(Request::exists, "HEAD"); } + public void testIndicesExist_OneIndex() { + final String indexName = randomAlphaOfLength(10); + IndicesExistsRequest indicesExistRequest = new IndicesExistsRequest(indexName); + final Request request = Request.indicesExist(indicesExistRequest); + assertEquals("/" + indexName, request.getEndpoint()); + assertEquals("HEAD", request.getMethod()); + } + + public void testIndicesExist_OneIndexExists_OneDoesnt() { + final String index1 = randomAlphaOfLength(10); + final String index2 = randomAlphaOfLength(10); + + IndicesExistsRequest indicesExistRequest = new IndicesExistsRequest(index1, index2); + final Request request = Request.indicesExist(indicesExistRequest); + assertEquals("/" + index1 + "," + index2, request.getEndpoint()); + assertEquals("HEAD", request.getMethod()); + } + private static void getAndExistsTest(Function requestConverter, String method) { String index = randomAlphaOfLengthBetween(3, 10); String type = randomAlphaOfLengthBetween(3, 10); From 2e4d42a15fbff6253843991a101e541dc04e63a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Tue, 14 Nov 2017 16:52:41 +0100 Subject: [PATCH 04/25] Reverted change (obsolete type declaration) --- .../src/main/java/org/elasticsearch/client/Request.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e3eb74a8493c2..069683756b1b3 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 @@ -414,7 +414,7 @@ static String endpoint(String... parts) { * @return the {@link ContentType} */ @SuppressForbidden(reason = "Only allowed place to convert a XContentType to a ContentType") - public static ContentType createContentType(final XContentType xContentType) { + public static ContentType createContentType(final XContentType xContentType) { return ContentType.create(xContentType.mediaTypeWithoutParameters(), (Charset) null); } From e57d2ff0aba6d08c65db2bd4411cbd355e5c1903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Tue, 14 Nov 2017 16:58:15 +0100 Subject: [PATCH 05/25] Removed useless code. --- .../org/elasticsearch/client/IndicesClient.java | 2 +- .../client/ESRestHighLevelClientTestCase.java | 2 +- .../exists/indices/IndicesExistsResponse.java | 16 ++-------------- 3 files changed, 4 insertions(+), 16 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 7da839bd23b48..4b0f17e64fbea 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 @@ -78,7 +78,7 @@ private IndicesExistsResponse parseIndicesExistResp(Response response) { return new IndicesExistsResponse(response.getStatusLine().getStatusCode() == 200); } - public void existsAsync(IndicesExistsRequest indicesExistsRequest, ActionListener listener, Header... headers) throws IOException { + public void existsAsync(IndicesExistsRequest indicesExistsRequest, ActionListener listener, Header... headers) { restHighLevelClient.performRequestAsync( indicesExistsRequest, Request::indicesExist, diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java index dfcca29ffd2b6..aabe2c4d1e270 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/ESRestHighLevelClientTestCase.java @@ -72,7 +72,7 @@ protected interface SyncMethod { @FunctionalInterface protected interface AsyncMethod { - void execute(Request request, ActionListener listener, Header... headers) throws IOException; + void execute(Request request, ActionListener listener, Header... headers); } private static class HighLevelClient extends RestHighLevelClient { diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsResponse.java b/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsResponse.java index b7b5ce33c2841..fb2d5c0fa9b9c 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/exists/indices/IndicesExistsResponse.java @@ -22,13 +22,10 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.ToXContentObject; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; -public class IndicesExistsResponse extends ActionResponse implements ToXContentObject { +public class IndicesExistsResponse extends ActionResponse { private boolean exists; @@ -54,13 +51,4 @@ public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeBoolean(exists); } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - return null; - } - - public static IndicesExistsResponse fromXContent(XContentParser xContentParser) { - return null; - } -} \ No newline at end of file +} From abf291947178ffe3d80dfecf2b3c61ffd6e70505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Tue, 14 Nov 2017 17:23:48 +0100 Subject: [PATCH 06/25] Updated docs. --- docs/java-rest/high-level/supported-apis.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index 9e902e1715766..d9a08c1ede4e8 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.asciidoc @@ -5,6 +5,7 @@ The Java High Level REST Client supports the following APIs: Indices APIs:: * <> +* <> Single document APIs:: * <> From a63880fa2f4461e7ca87b9b5cda987f57e0e51d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Fri, 1 Dec 2017 18:08:35 +0100 Subject: [PATCH 07/25] Code improvements. --- .../elasticsearch/client/IndicesClient.java | 23 ++++++++++++++----- .../org/elasticsearch/client/Request.java | 14 ++++------- .../elasticsearch/client/IndicesClientIT.java | 6 ++--- 3 files changed, 25 insertions(+), 18 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 4b0f17e64fbea..014d299bee51d 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 @@ -27,8 +27,7 @@ import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; import java.io.IOException; - -import static java.util.Collections.emptySet; +import java.util.Collections; /** * A wrapper for the {@link RestHighLevelClient} that provides methods for accessing the Indices API. @@ -50,7 +49,7 @@ public IndicesClient(RestHighLevelClient restHighLevelClient) { */ public DeleteIndexResponse deleteIndex(DeleteIndexRequest deleteIndexRequest, Header... headers) throws IOException { return restHighLevelClient.performRequestAndParseEntity(deleteIndexRequest, Request::deleteIndex, DeleteIndexResponse::fromXContent, - emptySet(), headers); + Collections.emptySet(), headers); } /** @@ -61,15 +60,21 @@ public DeleteIndexResponse deleteIndex(DeleteIndexRequest deleteIndexRequest, He */ public void deleteIndexAsync(DeleteIndexRequest deleteIndexRequest, ActionListener listener, Header... headers) { restHighLevelClient.performRequestAsyncAndParseEntity(deleteIndexRequest, Request::deleteIndex, DeleteIndexResponse::fromXContent, - listener, emptySet(), headers); + listener, Collections.emptySet(), headers); } + /** + * Checks if the index (indices) exists or not. + *

+ * See + * Indices Exists API on elastic.co + */ public IndicesExistsResponse exists(IndicesExistsRequest indicesExistsRequest, Header... headers) throws IOException { return restHighLevelClient.performRequest( indicesExistsRequest, Request::indicesExist, this::parseIndicesExistResp, - emptySet(), + Collections.emptySet(), headers ); } @@ -78,13 +83,19 @@ private IndicesExistsResponse parseIndicesExistResp(Response response) { return new IndicesExistsResponse(response.getStatusLine().getStatusCode() == 200); } + /** + * Asynchronously checks if the index (indices) exists or not. + *

+ * See + * Indices Exists API on elastic.co + */ public void existsAsync(IndicesExistsRequest indicesExistsRequest, ActionListener listener, Header... headers) { restHighLevelClient.performRequestAsync( indicesExistsRequest, Request::indicesExist, this::parseIndicesExistResp, listener, - emptySet(), + 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 069683756b1b3..c7af8158a9f5a 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 @@ -28,7 +28,6 @@ import org.apache.http.entity.ByteArrayEntity; import org.apache.http.entity.ContentType; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.DocWriteRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; @@ -69,8 +68,6 @@ import java.util.Objects; import java.util.StringJoiner; -import static java.util.Collections.emptyMap; - public final class Request { static final XContentType REQUEST_BODY_CONTENT_TYPE = XContentType.JSON; @@ -140,7 +137,7 @@ static Request deleteIndex(DeleteIndexRequest deleteIndexRequest) { } static Request info() { - return new Request(HttpGet.METHOD_NAME, "/", emptyMap(), null); + return new Request(HttpGet.METHOD_NAME, "/", Collections.emptyMap(), null); } static Request bulk(BulkRequest bulkRequest) throws IOException { @@ -310,7 +307,7 @@ static Request index(IndexRequest indexRequest) { } static Request ping() { - return new Request(HttpHead.METHOD_NAME, "/", emptyMap(), null); + return new Request(HttpHead.METHOD_NAME, "/", Collections.emptyMap(), null); } static Request update(UpdateRequest updateRequest) throws IOException { @@ -377,12 +374,12 @@ static Request search(SearchRequest searchRequest) throws IOException { static Request searchScroll(SearchScrollRequest searchScrollRequest) throws IOException { HttpEntity entity = createEntity(searchScrollRequest, REQUEST_BODY_CONTENT_TYPE); - return new Request("GET", "/_search/scroll", emptyMap(), entity); + return new Request("GET", "/_search/scroll", Collections.emptyMap(), entity); } static Request clearScroll(ClearScrollRequest clearScrollRequest) throws IOException { HttpEntity entity = createEntity(clearScrollRequest, REQUEST_BODY_CONTENT_TYPE); - return new Request("DELETE", "/_search/scroll", emptyMap(), entity); + return new Request("DELETE", "/_search/scroll", Collections.emptyMap(), entity); } private static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType) throws IOException { @@ -420,8 +417,7 @@ public static ContentType createContentType(final XContentType xContentType) { static Request indicesExist(IndicesExistsRequest request) { String endpoint = endpoint(request.indices(), Strings.EMPTY_ARRAY, ""); - - return new Request(HttpHead.METHOD_NAME, endpoint, emptyMap(), null); + return new Request(HttpHead.METHOD_NAME, endpoint, Collections.emptyMap(), null); } /** 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 c30d80c71531e..df4d82ceb7c2d 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 @@ -30,7 +30,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase { - public void testIndexExists_IndexPresent() throws IOException { + public void testIndexExistsIfIndexPresent() throws IOException { // Delete index if exists String indexName = "test_index_exists_index_present"; createIndex(indexName); @@ -44,7 +44,7 @@ public void testIndexExists_IndexPresent() throws IOException { assertTrue(response.isExists()); } - public void testIndexExists_IndexNotPresent() throws IOException { + public void testIndexExistsIfIndexNotPresent() throws IOException { String indexName = "non_existent_index"; IndicesExistsRequest request = new IndicesExistsRequest(indexName); @@ -56,7 +56,7 @@ public void testIndexExists_IndexNotPresent() throws IOException { assertFalse(response.isExists()); } - public void testIndexExists_OneIndexPresent_OneIsnt() throws IOException { + public void testIndexExistsIfOneIndexPresent_OneIsnt() throws IOException { String existingIndex = "test_index_exists_index_present"; createIndex(existingIndex); From b1379b698222048a0514bdb1a6c23c149f877c8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Fri, 26 Jan 2018 15:17:33 +0100 Subject: [PATCH 08/25] Reused existing method. Params parsing. --- .../org/elasticsearch/client/IndicesClient.java | 12 ++++-------- .../main/java/org/elasticsearch/client/Request.java | 6 +++++- .../org/elasticsearch/client/IndicesClientIT.java | 13 ++++++------- 3 files changed, 15 insertions(+), 16 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 014d299bee51d..faeebb885ca28 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 @@ -69,31 +69,27 @@ public void deleteIndexAsync(DeleteIndexRequest deleteIndexRequest, ActionListen * See * Indices Exists API on elastic.co */ - public IndicesExistsResponse exists(IndicesExistsRequest indicesExistsRequest, Header... headers) throws IOException { + public final boolean exists(IndicesExistsRequest indicesExistsRequest, Header... headers) throws IOException { return restHighLevelClient.performRequest( indicesExistsRequest, Request::indicesExist, - this::parseIndicesExistResp, + RestHighLevelClient::convertExistsResponse, Collections.emptySet(), headers ); } - private IndicesExistsResponse parseIndicesExistResp(Response response) { - return new IndicesExistsResponse(response.getStatusLine().getStatusCode() == 200); - } - /** * Asynchronously checks if the index (indices) exists or not. *

* See * Indices Exists API on elastic.co */ - public void existsAsync(IndicesExistsRequest indicesExistsRequest, ActionListener listener, Header... headers) { + public final void existsAsync(IndicesExistsRequest indicesExistsRequest, ActionListener listener, Header... headers) { restHighLevelClient.performRequestAsync( indicesExistsRequest, Request::indicesExist, - this::parseIndicesExistResp, + RestHighLevelClient::convertExistsResponse, 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 c7af8158a9f5a..f75003f08bce1 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 @@ -417,7 +417,11 @@ public static ContentType createContentType(final XContentType xContentType) { static Request indicesExist(IndicesExistsRequest request) { String endpoint = endpoint(request.indices(), Strings.EMPTY_ARRAY, ""); - return new Request(HttpHead.METHOD_NAME, endpoint, Collections.emptyMap(), null); + Params params = Params.builder(); + params.putParam("local", Boolean.FALSE.toString()); + params.putParam("ignore_unavailable", Boolean.FALSE.toString()); + params.putParam("allow_no_indices", Boolean.FALSE.toString()); + return new Request(HttpHead.METHOD_NAME, endpoint, params.getParams(), null); } /** 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 df4d82ceb7c2d..88088ae821f0d 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 @@ -23,7 +23,6 @@ import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; -import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; import org.elasticsearch.rest.RestStatus; import java.io.IOException; @@ -36,24 +35,24 @@ public void testIndexExistsIfIndexPresent() throws IOException { createIndex(indexName); IndicesExistsRequest request = new IndicesExistsRequest(indexName); - IndicesExistsResponse response = execute( + boolean response = execute( request, highLevelClient().indices()::exists, highLevelClient().indices()::existsAsync ); - assertTrue(response.isExists()); + assertTrue(response); } public void testIndexExistsIfIndexNotPresent() throws IOException { String indexName = "non_existent_index"; IndicesExistsRequest request = new IndicesExistsRequest(indexName); - IndicesExistsResponse response = execute( + boolean response = execute( request, highLevelClient().indices()::exists, highLevelClient().indices()::existsAsync ); - assertFalse(response.isExists()); + assertFalse(response); } public void testIndexExistsIfOneIndexPresent_OneIsnt() throws IOException { @@ -63,12 +62,12 @@ public void testIndexExistsIfOneIndexPresent_OneIsnt() throws IOException { String nonExistentIndex = "non_existent_index"; IndicesExistsRequest request = new IndicesExistsRequest(existingIndex, nonExistentIndex); - IndicesExistsResponse response = execute( + boolean response = execute( request, highLevelClient().indices()::exists, highLevelClient().indices()::existsAsync ); - assertFalse(response.isExists()); + assertFalse(response); } public void testDeleteIndex() throws IOException { From 2ea0363bc392c873d56512e8959a3e46b1d3a047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Fri, 26 Jan 2018 16:46:02 +0100 Subject: [PATCH 09/25] Updated tests. Added more params. --- .../org/elasticsearch/client/Request.java | 7 +++++-- .../elasticsearch/client/RequestTests.java | 20 +++++++------------ 2 files changed, 12 insertions(+), 15 deletions(-) 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 f75003f08bce1..53fd4bcdaf1e0 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 @@ -419,8 +419,11 @@ static Request indicesExist(IndicesExistsRequest request) { String endpoint = endpoint(request.indices(), Strings.EMPTY_ARRAY, ""); Params params = Params.builder(); params.putParam("local", Boolean.FALSE.toString()); - params.putParam("ignore_unavailable", Boolean.FALSE.toString()); - params.putParam("allow_no_indices", Boolean.FALSE.toString()); + params.putParam("ignore_unavailable", String.valueOf(request.indicesOptions().ignoreUnavailable())); + params.putParam("allow_no_indices", String.valueOf(request.indicesOptions().allowNoIndices())); + params.putParam("expand_wildcards", "open"); + params.putParam("flat_settings", Boolean.FALSE.toString()); + params.putParam("include_defaults", Boolean.FALSE.toString()); return new Request(HttpHead.METHOD_NAME, endpoint, params.getParams(), null); } 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 7bc197a5ee395..5a702d75cacc1 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 @@ -80,6 +80,7 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; +import java.util.stream.IntStream; import static java.util.Collections.singletonMap; import static org.elasticsearch.client.Request.enforceSameContentType; @@ -174,21 +175,14 @@ public void testExists() { getAndExistsTest(Request::exists, "HEAD"); } - public void testIndicesExist_OneIndex() { - final String indexName = randomAlphaOfLength(10); - IndicesExistsRequest indicesExistRequest = new IndicesExistsRequest(indexName); - final Request request = Request.indicesExist(indicesExistRequest); - assertEquals("/" + indexName, request.getEndpoint()); - assertEquals("HEAD", request.getMethod()); - } + public void testIndicesExist() { + String[] indices = IntStream.range(1, randomIntBetween(1, 10)) + .mapToObj(i -> randomAlphaOfLength(10)) + .toArray(String[]::new); - public void testIndicesExist_OneIndexExists_OneDoesnt() { - final String index1 = randomAlphaOfLength(10); - final String index2 = randomAlphaOfLength(10); - - IndicesExistsRequest indicesExistRequest = new IndicesExistsRequest(index1, index2); + IndicesExistsRequest indicesExistRequest = new IndicesExistsRequest(indices); final Request request = Request.indicesExist(indicesExistRequest); - assertEquals("/" + index1 + "," + index2, request.getEndpoint()); + assertEquals("/" + String.join(",", indices), request.getEndpoint()); assertEquals("HEAD", request.getMethod()); } From 902aa9b88e9f78509ba9b29be43b74334f13eb7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Fri, 26 Jan 2018 17:00:45 +0100 Subject: [PATCH 10/25] Changed test name to be according to convention. --- .../src/test/java/org/elasticsearch/client/IndicesClientIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 88088ae821f0d..97d10a073d91d 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 @@ -55,7 +55,7 @@ public void testIndexExistsIfIndexNotPresent() throws IOException { assertFalse(response); } - public void testIndexExistsIfOneIndexPresent_OneIsnt() throws IOException { + public void testIndexExistsIfOneIndexPresentOneIsnt() throws IOException { String existingIndex = "test_index_exists_index_present"; createIndex(existingIndex); From c5af2e74976d2ce3cf3168b46ad6b747d8af2620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Fri, 26 Jan 2018 17:34:50 +0100 Subject: [PATCH 11/25] Small refactoring in Request.Params --- .../org/elasticsearch/client/Request.java | 22 ++++++++++++++----- .../elasticsearch/client/RequestTests.java | 3 ++- 2 files changed, 19 insertions(+), 6 deletions(-) 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 53fd4bcdaf1e0..069aa6d6b68c4 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 @@ -419,11 +419,9 @@ static Request indicesExist(IndicesExistsRequest request) { String endpoint = endpoint(request.indices(), Strings.EMPTY_ARRAY, ""); Params params = Params.builder(); params.putParam("local", Boolean.FALSE.toString()); - params.putParam("ignore_unavailable", String.valueOf(request.indicesOptions().ignoreUnavailable())); - params.putParam("allow_no_indices", String.valueOf(request.indicesOptions().allowNoIndices())); - params.putParam("expand_wildcards", "open"); - params.putParam("flat_settings", Boolean.FALSE.toString()); - params.putParam("include_defaults", Boolean.FALSE.toString()); + params.withIndicesOptions(request.indicesOptions()); + params.withFlatSettings(false); + params.withIncludeDefaults(false); return new Request(HttpHead.METHOD_NAME, endpoint, params.getParams(), null); } @@ -574,6 +572,20 @@ Params withIndicesOptions(IndicesOptions indicesOptions) { return this; } + Params withFlatSettings(boolean flatSettings) { + if (flatSettings) { + return putParam("flat_settings", Boolean.TRUE.toString()); + } + return this; + } + + Params withIncludeDefaults(boolean includeDefaults) { + if (includeDefaults) { + return putParam("include_defaults", Boolean.TRUE.toString()); + } + return this; + } + Map getParams() { return Collections.unmodifiableMap(params); } 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 5a702d75cacc1..61160718329c0 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 @@ -20,6 +20,7 @@ package org.elasticsearch.client; import org.apache.http.HttpEntity; +import org.apache.http.client.methods.HttpHead; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; @@ -183,7 +184,7 @@ public void testIndicesExist() { IndicesExistsRequest indicesExistRequest = new IndicesExistsRequest(indices); final Request request = Request.indicesExist(indicesExistRequest); assertEquals("/" + String.join(",", indices), request.getEndpoint()); - assertEquals("HEAD", request.getMethod()); + assertEquals(HttpHead.METHOD_NAME, request.getMethod()); } private static void getAndExistsTest(Function requestConverter, String method) { From a14e05b2801dec3e7c6c0c7ce936c864a35b1398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Fri, 26 Jan 2018 17:38:29 +0100 Subject: [PATCH 12/25] Handling the 'local' param. --- .../src/main/java/org/elasticsearch/client/Request.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 069aa6d6b68c4..04cb744caa6fb 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 @@ -418,7 +418,7 @@ public static ContentType createContentType(final XContentType xContentType) { static Request indicesExist(IndicesExistsRequest request) { String endpoint = endpoint(request.indices(), Strings.EMPTY_ARRAY, ""); Params params = Params.builder(); - params.putParam("local", Boolean.FALSE.toString()); + params.withLocal(request.local()); params.withIndicesOptions(request.indicesOptions()); params.withFlatSettings(false); params.withIncludeDefaults(false); @@ -572,6 +572,13 @@ Params withIndicesOptions(IndicesOptions indicesOptions) { return this; } + Params withLocal(boolean local) { + if (local) { + return putParam("local", Boolean.TRUE.toString()); + } + return this; + } + Params withFlatSettings(boolean flatSettings) { if (flatSettings) { return putParam("flat_settings", Boolean.TRUE.toString()); From 18e2c925043fe73ff622514d7c5ecfad1e142a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Fri, 26 Jan 2018 19:21:00 +0100 Subject: [PATCH 13/25] Reused existing method. --- .../src/test/java/org/elasticsearch/client/RequestTests.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 960dca959d310..a7bd4dac5c153 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 @@ -252,9 +252,7 @@ public void testExists() { } public void testIndicesExist() { - String[] indices = IntStream.range(1, randomIntBetween(1, 10)) - .mapToObj(i -> randomAlphaOfLength(10)) - .toArray(String[]::new); + String[] indices = randomIndicesNames(1, 10); IndicesExistsRequest indicesExistRequest = new IndicesExistsRequest(indices); final Request request = Request.indicesExist(indicesExistRequest); From 3491962c46be5b7f152e49397f690a0b30cf7ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Fri, 26 Jan 2018 19:39:13 +0100 Subject: [PATCH 14/25] Testing linking in ascii docs. --- docs/java-rest/high-level/apis/indices_exists.asciidoc | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 docs/java-rest/high-level/apis/indices_exists.asciidoc diff --git a/docs/java-rest/high-level/apis/indices_exists.asciidoc b/docs/java-rest/high-level/apis/indices_exists.asciidoc new file mode 100644 index 0000000000000..ee6dca86e7328 --- /dev/null +++ b/docs/java-rest/high-level/apis/indices_exists.asciidoc @@ -0,0 +1,6 @@ +[[java-rest-high-indices-exists]] +=== Indices Exists API + +==== Indices Exists Request + +An `IndicesExistsRequest` requires an `indices` argument, which is an array of index names. \ No newline at end of file From 3aad6c17cdfd0c227db877f724f9f41db0edd1aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Mon, 29 Jan 2018 12:13:36 +0100 Subject: [PATCH 15/25] Add flat_settings and include_defaults to GetIndexRequest. --- .../org/elasticsearch/client/Request.java | 7 ++++--- .../admin/indices/get/GetIndexRequest.java | 21 ++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) 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 d2a82882bd1e1..ac7341ffcbd9a 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 @@ -35,6 +35,7 @@ import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; +import org.elasticsearch.action.admin.indices.get.GetIndexRequest; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; import org.elasticsearch.action.bulk.BulkRequest; @@ -542,13 +543,13 @@ public static ContentType createContentType(final XContentType xContentType) { return ContentType.create(xContentType.mediaTypeWithoutParameters(), (Charset) null); } - static Request indicesExist(IndicesExistsRequest request) { + static Request indicesExist(GetIndexRequest request) { String endpoint = endpoint(request.indices(), Strings.EMPTY_ARRAY, ""); Params params = Params.builder(); params.withLocal(request.local()); params.withIndicesOptions(request.indicesOptions()); - params.withFlatSettings(false); - params.withIncludeDefaults(false); + params.withFlatSettings(request.flatSettings()); + params.withIncludeDefaults(request.includeDefaults()); return new Request(HttpHead.METHOD_NAME, endpoint, params.getParams(), null); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexRequest.java index 0177799c8fd4b..a95c8bc329f85 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexRequest.java @@ -33,7 +33,6 @@ * A request to delete an index. Best created with {@link org.elasticsearch.client.Requests#deleteIndexRequest(String)}. */ public class GetIndexRequest extends ClusterInfoRequest { - public enum Feature { ALIASES((byte) 0, "_aliases", "_alias"), MAPPINGS((byte) 1, "_mappings", "_mapping"), @@ -99,6 +98,8 @@ public static Feature[] convertToFeatures(String... featureNames) { private static final Feature[] DEFAULT_FEATURES = new Feature[] { Feature.ALIASES, Feature.MAPPINGS, Feature.SETTINGS }; private Feature[] features = DEFAULT_FEATURES; private boolean humanReadable = false; + private boolean flatSettings = false; + private boolean includeDefaults = false; public GetIndexRequest() { @@ -149,6 +150,24 @@ public boolean humanReadable() { return humanReadable; } + public GetIndexRequest flatSettings(boolean flatSettings) { + this.flatSettings = flatSettings; + return this; + } + + public boolean flatSettings() { + return flatSettings; + } + + public GetIndexRequest includeDefaults(boolean includeDefaults) { + this.includeDefaults = includeDefaults; + return this; + } + + public boolean includeDefaults() { + return includeDefaults; + } + @Override public void readFrom(StreamInput in) throws IOException { throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); From 0e6adfa0ad92ef269d139643defa3f56ab324d52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Mon, 29 Jan 2018 17:07:57 +0100 Subject: [PATCH 16/25] Replace IndicesExistRequest in HLRC with GetIndexRequest. --- .../elasticsearch/client/IndicesClient.java | 14 +++---- .../elasticsearch/client/IndicesClientIT.java | 13 +++++-- .../elasticsearch/client/RequestTests.java | 38 ++++++++++++++++--- .../high-level/apis/indices_exists.asciidoc | 1 - 4 files changed, 49 insertions(+), 17 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 b289479834144..4ac614fe41457 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,16 +21,16 @@ import org.apache.http.Header; import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; +import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; import org.elasticsearch.action.admin.indices.close.CloseIndexResponse; -import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; -import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; 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.exists.indices.IndicesExistsRequest; +import org.elasticsearch.action.admin.indices.get.GetIndexRequest; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; @@ -217,9 +217,9 @@ public void existsAliasAsync(GetAliasesRequest getAliasesRequest, ActionListener * See * Indices Exists API on elastic.co */ - public final boolean exists(IndicesExistsRequest indicesExistsRequest, Header... headers) throws IOException { + public final boolean exists(GetIndexRequest request, Header... headers) throws IOException { return restHighLevelClient.performRequest( - indicesExistsRequest, + request, Request::indicesExist, RestHighLevelClient::convertExistsResponse, Collections.emptySet(), @@ -233,9 +233,9 @@ public final boolean exists(IndicesExistsRequest indicesExistsRequest, Header... * See * Indices Exists API on elastic.co */ - public final void existsAsync(IndicesExistsRequest indicesExistsRequest, ActionListener listener, Header... headers) { + public final void existsAsync(GetIndexRequest request, ActionListener listener, Header... headers) { restHighLevelClient.performRequestAsync( - indicesExistsRequest, + request, Request::indicesExist, RestHighLevelClient::convertExistsResponse, listener, 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 84db27fb6f99e..76ca9a890927d 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 @@ -37,6 +37,7 @@ import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; +import org.elasticsearch.action.admin.indices.get.GetIndexRequest; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; @@ -65,7 +66,9 @@ public void testIndexExistsIfIndexPresent() throws IOException { String indexName = "test_index_exists_index_present"; createIndex(indexName); - IndicesExistsRequest request = new IndicesExistsRequest(indexName); + GetIndexRequest request = new GetIndexRequest(); + request.indices(indexName); + boolean response = execute( request, highLevelClient().indices()::exists, @@ -77,7 +80,9 @@ public void testIndexExistsIfIndexPresent() throws IOException { public void testIndexExistsIfIndexNotPresent() throws IOException { String indexName = "non_existent_index"; - IndicesExistsRequest request = new IndicesExistsRequest(indexName); + GetIndexRequest request = new GetIndexRequest(); + request.indices(indexName); + boolean response = execute( request, highLevelClient().indices()::exists, @@ -92,7 +97,9 @@ public void testIndexExistsIfOneIndexPresentOneIsnt() throws IOException { String nonExistentIndex = "non_existent_index"; - IndicesExistsRequest request = new IndicesExistsRequest(existingIndex, nonExistentIndex); + GetIndexRequest request = new GetIndexRequest(); + request.indices(existingIndex, nonExistentIndex); + boolean response = execute( request, highLevelClient().indices()::exists, 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 38b3dd8a88c22..75e4d8568d93e 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 @@ -30,13 +30,14 @@ import org.apache.http.entity.StringEntity; import org.apache.http.util.EntityUtils; import org.elasticsearch.action.DocWriteRequest; -import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; -import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; +import org.elasticsearch.action.IndicesRequest; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; +import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; +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.exists.indices.IndicesExistsRequest; +import org.elasticsearch.action.admin.indices.get.GetIndexRequest; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; import org.elasticsearch.action.bulk.BulkRequest; @@ -98,7 +99,6 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; -import java.util.stream.IntStream; import static java.util.Collections.singletonMap; import static org.elasticsearch.client.Request.REQUEST_BODY_CONTENT_TYPE; @@ -253,10 +253,36 @@ public void testExists() { public void testIndicesExist() { String[] indices = randomIndicesNames(1, 10); + boolean flatSettings = true; + boolean includeDefaults = true; + boolean local = true; + boolean ignoreUnavailable = false; + boolean allowNoIndices = true; + boolean expandToOpenIndices = false; + boolean expandToClosedIndices = false; + + IndicesOptions indicesOptions = IndicesOptions.fromOptions( + ignoreUnavailable, + allowNoIndices, + expandToOpenIndices, + expandToClosedIndices + ); + GetIndexRequest getIndexRequest = new GetIndexRequest() + .local(local) + .indicesOptions(indicesOptions) + .indices(indices) + .flatSettings(flatSettings) + .includeDefaults(includeDefaults); + + final Request request = Request.indicesExist(getIndexRequest); - IndicesExistsRequest indicesExistRequest = new IndicesExistsRequest(indices); - final Request request = Request.indicesExist(indicesExistRequest); assertEquals("/" + String.join(",", indices), request.getEndpoint()); + assertEquals(String.valueOf(flatSettings), request.getParameters().get("flat_settings")); + assertEquals(String.valueOf(local), request.getParameters().get("local")); + assertEquals(String.valueOf(includeDefaults), request.getParameters().get("include_defaults")); + assertEquals(String.valueOf(ignoreUnavailable), request.getParameters().get("ignore_unavailable")); + assertEquals(String.valueOf(allowNoIndices), request.getParameters().get("allow_no_indices")); + assertEquals("none", request.getParameters().get("expand_wildcards")); assertEquals(HttpHead.METHOD_NAME, request.getMethod()); } diff --git a/docs/java-rest/high-level/apis/indices_exists.asciidoc b/docs/java-rest/high-level/apis/indices_exists.asciidoc index ee6dca86e7328..9ba0098492f6e 100644 --- a/docs/java-rest/high-level/apis/indices_exists.asciidoc +++ b/docs/java-rest/high-level/apis/indices_exists.asciidoc @@ -3,4 +3,3 @@ ==== Indices Exists Request -An `IndicesExistsRequest` requires an `indices` argument, which is an array of index names. \ No newline at end of file From 53d226c746faaf4fff89339dd852114ba87d6385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Tue, 30 Jan 2018 17:31:35 +0100 Subject: [PATCH 17/25] Added 'human' parameter. Updated docs. --- .../org/elasticsearch/client/Request.java | 6 ++++ .../elasticsearch/client/RequestTests.java | 4 +++ .../IndicesClientDocumentationIT.java | 30 +++++++++++++++++++ docs/java-rest/high-level/apis/index.asciidoc | 2 ++ .../high-level/apis/indices_exists.asciidoc | 23 ++++++++++++++ 5 files changed, 65 insertions(+) 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 ac7341ffcbd9a..765adaee17430 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 @@ -547,6 +547,7 @@ static Request indicesExist(GetIndexRequest request) { String endpoint = endpoint(request.indices(), Strings.EMPTY_ARRAY, ""); Params params = Params.builder(); params.withLocal(request.local()); + params.withHuman(request.humanReadable()); params.withIndicesOptions(request.indicesOptions()); params.withFlatSettings(request.flatSettings()); params.withIncludeDefaults(request.includeDefaults()); @@ -700,6 +701,11 @@ Params withIndicesOptions(IndicesOptions indicesOptions) { return this; } + Params withHuman(boolean human) { + putParam("human", Boolean.toString(human)); + return this; + } + Params withLocal(boolean local) { putParam("local", Boolean.toString(local)); return this; 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 75e4d8568d93e..29514d5f8f2be 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 @@ -256,6 +256,7 @@ public void testIndicesExist() { boolean flatSettings = true; boolean includeDefaults = true; boolean local = true; + boolean humanReadable = true; boolean ignoreUnavailable = false; boolean allowNoIndices = true; boolean expandToOpenIndices = false; @@ -267,8 +268,10 @@ public void testIndicesExist() { expandToOpenIndices, expandToClosedIndices ); + GetIndexRequest getIndexRequest = new GetIndexRequest() .local(local) + .humanReadable(humanReadable) .indicesOptions(indicesOptions) .indices(indices) .flatSettings(flatSettings) @@ -279,6 +282,7 @@ public void testIndicesExist() { assertEquals("/" + String.join(",", indices), request.getEndpoint()); assertEquals(String.valueOf(flatSettings), request.getParameters().get("flat_settings")); assertEquals(String.valueOf(local), request.getParameters().get("local")); + assertEquals(String.valueOf(humanReadable), request.getParameters().get("human")); assertEquals(String.valueOf(includeDefaults), request.getParameters().get("include_defaults")); assertEquals(String.valueOf(ignoreUnavailable), request.getParameters().get("ignore_unavailable")); assertEquals(String.valueOf(allowNoIndices), request.getParameters().get("allow_no_indices")); 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 1bcfb0bbc24a0..d185ab5ea530d 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 @@ -19,6 +19,7 @@ package org.elasticsearch.client.documentation; +import org.apache.http.Header; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.alias.Alias; @@ -32,6 +33,7 @@ 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.get.GetIndexRequest; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; @@ -64,6 +66,34 @@ */ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase { + public void testIndicesExist() throws IOException { + RestHighLevelClient client = highLevelClient(); + + { + CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter")); + assertTrue(createIndexResponse.isAcknowledged()); + } + + { + // tag::indices-exists-request + GetIndexRequest request = new GetIndexRequest(); + request.indices("twitter"); // <1> + // end::indices-exists-request + + // tag::indices-exists-request-optionals + request.local(false); + request.humanReadable(true); + request.includeDefaults(false); + request.flatSettings(false); + // end::indices-exists-request-optionals + + Header[] headers = new Header[0]; + // tag::indices-exists-response + boolean exists = client.indices().exists(request, headers); + // end::indices-exists-response + assertTrue(exists); + } + } public void testDeleteIndex() throws IOException { RestHighLevelClient client = highLevelClient(); diff --git a/docs/java-rest/high-level/apis/index.asciidoc b/docs/java-rest/high-level/apis/index.asciidoc index 5f1f15b644799..a33173bafacb4 100644 --- a/docs/java-rest/high-level/apis/index.asciidoc +++ b/docs/java-rest/high-level/apis/index.asciidoc @@ -1,5 +1,7 @@ include::createindex.asciidoc[] +include::indices_exists.asciidoc[] + include::deleteindex.asciidoc[] include::open_index.asciidoc[] diff --git a/docs/java-rest/high-level/apis/indices_exists.asciidoc b/docs/java-rest/high-level/apis/indices_exists.asciidoc index 9ba0098492f6e..66320008e41d4 100644 --- a/docs/java-rest/high-level/apis/indices_exists.asciidoc +++ b/docs/java-rest/high-level/apis/indices_exists.asciidoc @@ -3,3 +3,26 @@ ==== Indices Exists Request +The high-level REST client uses a `GetIndexRequest` for Indices Exists API. The index name (or indices' names) are required. + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[indices-exists-request] +-------------------------------------------------- +<1> Index + +==== Optional arguments +Indices Exists API also accepts following optional arguments, through a `GetIndexRequest`: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[indices-exists-request-optionals] +-------------------------------------------------- + +==== Response +The response is a `boolean` value, indicating whether the index (or indices) exist: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[indices-exists-response] +-------------------------------------------------- From 659a252271cc41e1fa1827fb04243b47308c4153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Tue, 30 Jan 2018 17:51:19 +0100 Subject: [PATCH 18/25] Randomized tests. --- .../elasticsearch/client/RequestTests.java | 64 ++++++++++++++----- 1 file changed, 48 insertions(+), 16 deletions(-) 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 29514d5f8f2be..ffc9894541882 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 @@ -30,7 +30,6 @@ import org.apache.http.entity.StringEntity; import org.apache.http.util.EntityUtils; import org.elasticsearch.action.DocWriteRequest; -import org.elasticsearch.action.IndicesRequest; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest; @@ -253,14 +252,14 @@ public void testExists() { public void testIndicesExist() { String[] indices = randomIndicesNames(1, 10); - boolean flatSettings = true; - boolean includeDefaults = true; - boolean local = true; - boolean humanReadable = true; - boolean ignoreUnavailable = false; - boolean allowNoIndices = true; - boolean expandToOpenIndices = false; - boolean expandToClosedIndices = false; + boolean flatSettings = randomBoolean(); + boolean includeDefaults = randomBoolean(); + boolean local = randomBoolean(); + boolean humanReadable = randomBoolean(); + boolean ignoreUnavailable = randomBoolean(); + boolean allowNoIndices = randomBoolean(); + boolean expandToOpenIndices = randomBoolean(); + boolean expandToClosedIndices = randomBoolean(); IndicesOptions indicesOptions = IndicesOptions.fromOptions( ignoreUnavailable, @@ -280,16 +279,49 @@ public void testIndicesExist() { final Request request = Request.indicesExist(getIndexRequest); assertEquals("/" + String.join(",", indices), request.getEndpoint()); - assertEquals(String.valueOf(flatSettings), request.getParameters().get("flat_settings")); - assertEquals(String.valueOf(local), request.getParameters().get("local")); - assertEquals(String.valueOf(humanReadable), request.getParameters().get("human")); - assertEquals(String.valueOf(includeDefaults), request.getParameters().get("include_defaults")); - assertEquals(String.valueOf(ignoreUnavailable), request.getParameters().get("ignore_unavailable")); - assertEquals(String.valueOf(allowNoIndices), request.getParameters().get("allow_no_indices")); - assertEquals("none", request.getParameters().get("expand_wildcards")); + assertEquals( + flatSettings, + Boolean.valueOf(request.getParameters().get("flat_settings")) + ); + assertEquals( + local, + Boolean.valueOf(request.getParameters().get("local")) + ); + assertEquals( + humanReadable, + Boolean.valueOf(request.getParameters().get("human")) + ); + assertEquals( + includeDefaults, + Boolean.valueOf(request.getParameters().get("include_defaults")) + ); + assertEquals( + ignoreUnavailable, + Boolean.valueOf(request.getParameters().get("ignore_unavailable")) + ); + assertEquals( + allowNoIndices, + Boolean.valueOf(request.getParameters().get("allow_no_indices")) + ); + assertEquals( + getWildcardValue(expandToOpenIndices, expandToClosedIndices), + request.getParameters().get("expand_wildcards") + ); assertEquals(HttpHead.METHOD_NAME, request.getMethod()); } + private String getWildcardValue(boolean expandToOpenIndices, boolean expandToClosedIndices) { + if (expandToOpenIndices && expandToClosedIndices) { + return "open,closed"; + } else if (!expandToOpenIndices && !expandToClosedIndices) { + return "none"; + } if (expandToClosedIndices) { + return "closed"; + } else { + return "open"; + } + } + private static void getAndExistsTest(Function requestConverter, String method) { String index = randomAlphaOfLengthBetween(3, 10); String type = randomAlphaOfLengthBetween(3, 10); From d665b556545f18891078aa17937953e448289707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Wed, 31 Jan 2018 15:46:20 +0100 Subject: [PATCH 19/25] Refactored tests. --- .../org/elasticsearch/client/Request.java | 9 +- .../elasticsearch/client/RequestTests.java | 104 +++++++----------- 2 files changed, 46 insertions(+), 67 deletions(-) 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 765adaee17430..752ef3ab6000a 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 @@ -34,7 +34,6 @@ 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.exists.indices.IndicesExistsRequest; import org.elasticsearch.action.admin.indices.get.GetIndexRequest; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; @@ -702,12 +701,16 @@ Params withIndicesOptions(IndicesOptions indicesOptions) { } Params withHuman(boolean human) { - putParam("human", Boolean.toString(human)); + if (human) { + putParam("human", Boolean.toString(human)); + } return this; } Params withLocal(boolean local) { - putParam("local", Boolean.toString(local)); + if (local) { + putParam("local", Boolean.toString(local)); + } return this; } 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 ffc9894541882..230d5b2e8cdfc 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 @@ -54,6 +54,7 @@ import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.WriteRequest; import org.elasticsearch.action.support.master.AcknowledgedRequest; +import org.elasticsearch.action.support.master.MasterNodeReadRequest; import org.elasticsearch.action.support.master.MasterNodeRequest; import org.elasticsearch.action.support.replication.ReplicationRequest; import org.elasticsearch.action.update.UpdateRequest; @@ -252,74 +253,21 @@ public void testExists() { public void testIndicesExist() { String[] indices = randomIndicesNames(1, 10); - boolean flatSettings = randomBoolean(); - boolean includeDefaults = randomBoolean(); - boolean local = randomBoolean(); - boolean humanReadable = randomBoolean(); - boolean ignoreUnavailable = randomBoolean(); - boolean allowNoIndices = randomBoolean(); - boolean expandToOpenIndices = randomBoolean(); - boolean expandToClosedIndices = randomBoolean(); - - IndicesOptions indicesOptions = IndicesOptions.fromOptions( - ignoreUnavailable, - allowNoIndices, - expandToOpenIndices, - expandToClosedIndices - ); - - GetIndexRequest getIndexRequest = new GetIndexRequest() - .local(local) - .humanReadable(humanReadable) - .indicesOptions(indicesOptions) - .indices(indices) - .flatSettings(flatSettings) - .includeDefaults(includeDefaults); + + GetIndexRequest getIndexRequest = new GetIndexRequest().indices(indices); + + Map expectedParams = new HashMap<>(); + setRandomIndicesOptions(getIndexRequest::indicesOptions, getIndexRequest::indicesOptions, expectedParams); + setRandomLocal(getIndexRequest, expectedParams); + setRandomFlatSettings(getIndexRequest, expectedParams); + setRandomHumanReadable(getIndexRequest, expectedParams); + setRandomIncludeDefaults(getIndexRequest, expectedParams); final Request request = Request.indicesExist(getIndexRequest); - assertEquals("/" + String.join(",", indices), request.getEndpoint()); - assertEquals( - flatSettings, - Boolean.valueOf(request.getParameters().get("flat_settings")) - ); - assertEquals( - local, - Boolean.valueOf(request.getParameters().get("local")) - ); - assertEquals( - humanReadable, - Boolean.valueOf(request.getParameters().get("human")) - ); - assertEquals( - includeDefaults, - Boolean.valueOf(request.getParameters().get("include_defaults")) - ); - assertEquals( - ignoreUnavailable, - Boolean.valueOf(request.getParameters().get("ignore_unavailable")) - ); - assertEquals( - allowNoIndices, - Boolean.valueOf(request.getParameters().get("allow_no_indices")) - ); - assertEquals( - getWildcardValue(expandToOpenIndices, expandToClosedIndices), - request.getParameters().get("expand_wildcards") - ); assertEquals(HttpHead.METHOD_NAME, request.getMethod()); - } - - private String getWildcardValue(boolean expandToOpenIndices, boolean expandToClosedIndices) { - if (expandToOpenIndices && expandToClosedIndices) { - return "open,closed"; - } else if (!expandToOpenIndices && !expandToClosedIndices) { - return "none"; - } if (expandToClosedIndices) { - return "closed"; - } else { - return "open"; - } + assertEquals("/" + String.join(",", indices), request.getEndpoint()); + assertThat(expectedParams, equalTo(request.getParameters())); } private static void getAndExistsTest(Function requestConverter, String method) { @@ -1230,6 +1178,34 @@ private static void setRandomIndicesOptions(Consumer setter, Sup } } + private static void setRandomIncludeDefaults(GetIndexRequest request, Map expectedParams) { + if (randomBoolean()) { + request.includeDefaults(true); + expectedParams.put("include_defaults", Boolean.TRUE.toString()); + } + } + + private static void setRandomHumanReadable(GetIndexRequest request, Map expectedParams) { + if (randomBoolean()) { + request.humanReadable(true); + expectedParams.put("human", Boolean.TRUE.toString()); + } + } + + private static void setRandomFlatSettings(GetIndexRequest request, Map expectedParams) { + if (randomBoolean()) { + request.flatSettings(true); + expectedParams.put("flat_settings", Boolean.TRUE.toString()); + } + } + + private static void setRandomLocal(MasterNodeReadRequest request, Map expectedParams) { + if (randomBoolean()) { + request.local(true); + expectedParams.put("local", Boolean.TRUE.toString()); + } + } + private static void setRandomTimeout(Consumer setter, TimeValue defaultTimeout, Map expectedParams) { if (randomBoolean()) { String timeout = randomTimeValue(); From 3fd5006eeca6d044e447d27c8c780750935967df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Wed, 31 Jan 2018 18:47:09 +0100 Subject: [PATCH 20/25] Improved tests. --- .../elasticsearch/client/IndicesClient.java | 4 +-- .../elasticsearch/client/RequestTests.java | 28 +++++++++++++------ 2 files changed, 22 insertions(+), 10 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 4ac614fe41457..75647c9646298 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 @@ -217,7 +217,7 @@ public void existsAliasAsync(GetAliasesRequest getAliasesRequest, ActionListener * See * Indices Exists API on elastic.co */ - public final boolean exists(GetIndexRequest request, Header... headers) throws IOException { + public boolean exists(GetIndexRequest request, Header... headers) throws IOException { return restHighLevelClient.performRequest( request, Request::indicesExist, @@ -233,7 +233,7 @@ public final boolean exists(GetIndexRequest request, Header... headers) throws I * See * Indices Exists API on elastic.co */ - public final void existsAsync(GetIndexRequest request, ActionListener listener, Header... headers) { + public void existsAsync(GetIndexRequest request, ActionListener listener, Header... headers) { restHighLevelClient.performRequestAsync( request, Request::indicesExist, 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 230d5b2e8cdfc..0bcdf8c050dba 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 @@ -1180,29 +1180,41 @@ private static void setRandomIndicesOptions(Consumer setter, Sup private static void setRandomIncludeDefaults(GetIndexRequest request, Map expectedParams) { if (randomBoolean()) { - request.includeDefaults(true); - expectedParams.put("include_defaults", Boolean.TRUE.toString()); + boolean includeDefaults = randomBoolean(); + request.includeDefaults(includeDefaults); + if (includeDefaults) { + expectedParams.put("include_defaults", String.valueOf(includeDefaults)); + } } } private static void setRandomHumanReadable(GetIndexRequest request, Map expectedParams) { if (randomBoolean()) { - request.humanReadable(true); - expectedParams.put("human", Boolean.TRUE.toString()); + boolean humanReadable = randomBoolean(); + request.humanReadable(humanReadable); + if (humanReadable) { + expectedParams.put("human", String.valueOf(humanReadable)); + } } } private static void setRandomFlatSettings(GetIndexRequest request, Map expectedParams) { if (randomBoolean()) { - request.flatSettings(true); - expectedParams.put("flat_settings", Boolean.TRUE.toString()); + boolean flatSettings = randomBoolean(); + request.flatSettings(flatSettings); + if (flatSettings) { + expectedParams.put("flat_settings", String.valueOf(flatSettings)); + } } } private static void setRandomLocal(MasterNodeReadRequest request, Map expectedParams) { if (randomBoolean()) { - request.local(true); - expectedParams.put("local", Boolean.TRUE.toString()); + boolean local = randomBoolean(); + request.local(local); + if (local) { + expectedParams.put("local", String.valueOf(local)); + } } } From fe18f270989715aa4f8ba0b8e1f4dc99ed20f14f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Wed, 31 Jan 2018 19:11:04 +0100 Subject: [PATCH 21/25] more JavaDocs. --- .../admin/indices/get/GetIndexRequest.java | 19 +++++++++++++++++++ .../support/master/MasterNodeReadRequest.java | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexRequest.java index a95c8bc329f85..0f19ec9a6196e 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexRequest.java @@ -150,20 +150,39 @@ public boolean humanReadable() { return humanReadable; } + /** + * Sets the value of "flat_settings". + * @param flatSettings value of "flat_settings" flag to be set + * @return this request + */ public GetIndexRequest flatSettings(boolean flatSettings) { this.flatSettings = flatSettings; return this; } + /** + * Return settings in flat format. + * @return true if settings need to be returned in flat format; false otherwise. + */ public boolean flatSettings() { return flatSettings; } + /** + * Sets the value of "include_defaults". + * @param includeDefaults value of "include_defaults" to be set. + * @return this request + */ public GetIndexRequest includeDefaults(boolean includeDefaults) { this.includeDefaults = includeDefaults; return this; } + /** + * Whether to return all default settings for each of the indices. + * @return true if defaults settings for each of the indices need to returned; + * false otherwise. + */ public boolean includeDefaults() { return includeDefaults; } diff --git a/server/src/main/java/org/elasticsearch/action/support/master/MasterNodeReadRequest.java b/server/src/main/java/org/elasticsearch/action/support/master/MasterNodeReadRequest.java index 92578d7f33fb5..3045bef46b8d1 100644 --- a/server/src/main/java/org/elasticsearch/action/support/master/MasterNodeReadRequest.java +++ b/server/src/main/java/org/elasticsearch/action/support/master/MasterNodeReadRequest.java @@ -51,6 +51,11 @@ public final Request local(boolean local) { return (Request) this; } + /** + * Return local information, do not retrieve the state from master node (default: false). + * @return true if local information is to be returned; + * false if information is to be retrieved from master node (default). + */ public final boolean local() { return local; } From 9461afbcfa6507b7e4b3f3b1b5dfac370efde903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Wed, 31 Jan 2018 19:52:13 +0100 Subject: [PATCH 22/25] Updated docs. Fixed a test. --- .../elasticsearch/client/RequestTests.java | 7 +-- .../IndicesClientDocumentationIT.java | 43 +++++++++++++++++-- .../high-level/apis/indices_exists.asciidoc | 29 +++++++++++++ 3 files changed, 69 insertions(+), 10 deletions(-) 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 b225df729c5a2..0742da504488f 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 @@ -1028,12 +1028,7 @@ public void testExistsAlias() { String[] aliases = randomIndicesNames(indices.length == 0 ? 1 : 0, 5); getAliasesRequest.aliases(aliases); Map expectedParams = new HashMap<>(); - if (randomBoolean()) { - boolean local = randomBoolean(); - getAliasesRequest.local(local); - } - expectedParams.put("local", Boolean.toString(getAliasesRequest.local())); - + setRandomLocal(getAliasesRequest, expectedParams); setRandomIndicesOptions(getAliasesRequest::indicesOptions, getAliasesRequest::indicesOptions, expectedParams); Request request = Request.existsAlias(getAliasesRequest); 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 d185ab5ea530d..314865e90614a 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 @@ -80,11 +80,13 @@ public void testIndicesExist() throws IOException { request.indices("twitter"); // <1> // end::indices-exists-request + IndicesOptions indicesOptions = IndicesOptions.strictExpand(); // tag::indices-exists-request-optionals - request.local(false); - request.humanReadable(true); - request.includeDefaults(false); - request.flatSettings(false); + request.local(false); // <1> + request.humanReadable(true); // <2> + request.includeDefaults(false); // <3> + request.flatSettings(false); // <4> + request.indicesOptions(indicesOptions); // <5> // end::indices-exists-request-optionals Header[] headers = new Header[0]; @@ -94,6 +96,39 @@ public void testIndicesExist() throws IOException { assertTrue(exists); } } + + public void testIndicesExistAsync() throws IOException { + RestHighLevelClient client = highLevelClient(); + + { + CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter")); + assertTrue(createIndexResponse.isAcknowledged()); + } + + { + GetIndexRequest request = new GetIndexRequest(); + request.indices("twitter"); + Header[] headers = new Header[0]; + + // tag::indices-exists-async + client.indices().existsAsync( + request, + new ActionListener() { + @Override + public void onResponse(Boolean exists) { + // <1> + } + + @Override + public void onFailure(Exception e) { + // <2> + } + }, + headers + ); + // end::indices-exists-async + } + } public void testDeleteIndex() throws IOException { RestHighLevelClient client = highLevelClient(); diff --git a/docs/java-rest/high-level/apis/indices_exists.asciidoc b/docs/java-rest/high-level/apis/indices_exists.asciidoc index 66320008e41d4..65a6649622552 100644 --- a/docs/java-rest/high-level/apis/indices_exists.asciidoc +++ b/docs/java-rest/high-level/apis/indices_exists.asciidoc @@ -1,6 +1,7 @@ [[java-rest-high-indices-exists]] === Indices Exists API +[[java-rest-high-indices-exists-request]] ==== Indices Exists Request The high-level REST client uses a `GetIndexRequest` for Indices Exists API. The index name (or indices' names) are required. @@ -11,6 +12,7 @@ include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[indices-exists-req -------------------------------------------------- <1> Index +[[java-rest-high-indices-exists-optional-args]] ==== Optional arguments Indices Exists API also accepts following optional arguments, through a `GetIndexRequest`: @@ -18,7 +20,34 @@ Indices Exists API also accepts following optional arguments, through a `GetInde -------------------------------------------------- include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[indices-exists-request-optionals] -------------------------------------------------- +<1> Whether to return local information or retrieve the state from master node. +<2> Return result in a format suitable for humans. +<3> Whether to return all default setting for each of the indices. +<4> Return settings in flat format. +<5> Controls how unavailable indices are resolved and how wildcard expressions are expanded. +[[java-rest-high-indices-sync]] +==== Synchronous Execution +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[indices-exists-response] +-------------------------------------------------- + +[[java-rest-high-indices-async]] +==== Asynchronous Execution +As is the case with many other APIs, the Indices Exists API has an asynchronous variant in the +Java High Level REST Client. +The asynchronous variant returns void and accept an extra `ActionListener` as an argument. +The provided listener will be notified upon request completion or failure. + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[indices-exists-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-indices-exists-response]] ==== Response The response is a `boolean` value, indicating whether the index (or indices) exist: From 910cc95c16835658fc60eb2375da9e8aa66177bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Thu, 1 Feb 2018 19:41:04 +0100 Subject: [PATCH 23/25] Updated docs. Added another check to test. --- .../org/elasticsearch/client/RequestTests.java | 1 + .../high-level/apis/indices_exists.asciidoc | 14 +++++++------- .../action/admin/indices/get/GetIndexRequest.java | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) 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 0742da504488f..e4d2c0e553840 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 @@ -275,6 +275,7 @@ public void testIndicesExist() { assertEquals(HttpHead.METHOD_NAME, request.getMethod()); assertEquals("/" + String.join(",", indices), request.getEndpoint()); assertThat(expectedParams, equalTo(request.getParameters())); + assertNull(request.getEntity()); } private static void getAndExistsTest(Function requestConverter, String method) { diff --git a/docs/java-rest/high-level/apis/indices_exists.asciidoc b/docs/java-rest/high-level/apis/indices_exists.asciidoc index 65a6649622552..e5ae47ea17ece 100644 --- a/docs/java-rest/high-level/apis/indices_exists.asciidoc +++ b/docs/java-rest/high-level/apis/indices_exists.asciidoc @@ -20,11 +20,11 @@ Indices Exists API also accepts following optional arguments, through a `GetInde -------------------------------------------------- include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[indices-exists-request-optionals] -------------------------------------------------- -<1> Whether to return local information or retrieve the state from master node. -<2> Return result in a format suitable for humans. -<3> Whether to return all default setting for each of the indices. -<4> Return settings in flat format. -<5> Controls how unavailable indices are resolved and how wildcard expressions are expanded. +<1> Whether to return local information or retrieve the state from master node +<2> Return result in a format suitable for humans +<3> Whether to return all default setting for each of the indices +<4> Return settings in flat format +<5> Controls how unavailable indices are resolved and how wildcard expressions are expanded [[java-rest-high-indices-sync]] ==== Synchronous Execution @@ -44,8 +44,8 @@ The provided listener will be notified upon request completion or failure. -------------------------------------------------- include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[indices-exists-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. +<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-indices-exists-response]] ==== Response diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexRequest.java index 0f19ec9a6196e..43beba5b670c0 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexRequest.java @@ -98,8 +98,8 @@ public static Feature[] convertToFeatures(String... featureNames) { private static final Feature[] DEFAULT_FEATURES = new Feature[] { Feature.ALIASES, Feature.MAPPINGS, Feature.SETTINGS }; private Feature[] features = DEFAULT_FEATURES; private boolean humanReadable = false; - private boolean flatSettings = false; - private boolean includeDefaults = false; + private transient boolean flatSettings = false; + private transient boolean includeDefaults = false; public GetIndexRequest() { From 870fdfd224cbb5e653573ecdc0f1cf84e3ee94a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Fri, 2 Feb 2018 10:36:46 +0100 Subject: [PATCH 24/25] Fixed merge error. --- docs/java-rest/high-level/apis/index.asciidoc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/docs/java-rest/high-level/apis/index.asciidoc b/docs/java-rest/high-level/apis/index.asciidoc index 27da54898b9f8..8128de65bae07 100644 --- a/docs/java-rest/high-level/apis/index.asciidoc +++ b/docs/java-rest/high-level/apis/index.asciidoc @@ -1,12 +1,8 @@ include::create_index.asciidoc[] -<<<<<<< HEAD include::indices_exists.asciidoc[] -include::deleteindex.asciidoc[] -======= include::delete_index.asciidoc[] ->>>>>>> master include::open_index.asciidoc[] From 1f57a30d92d12bdbcc433b084c80d9e052ed62a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haris=20Osmanagi=C4=87?= Date: Fri, 2 Feb 2018 10:43:27 +0100 Subject: [PATCH 25/25] Combined tests. --- .../elasticsearch/client/IndicesClientIT.java | 80 ++++++++++--------- 1 file changed, 43 insertions(+), 37 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 6cd28efd7c4c3..5baef93c0dee1 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 @@ -59,50 +59,56 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase { - public void testIndexExistsIfIndexPresent() throws IOException { - String indexName = "test_index_exists_index_present"; - createIndex(indexName, Settings.EMPTY); - - GetIndexRequest request = new GetIndexRequest(); - request.indices(indexName); - - boolean response = execute( - request, - highLevelClient().indices()::exists, - highLevelClient().indices()::existsAsync - ); - assertTrue(response); - } + public void testIndicesExists() throws IOException { + // Index present + { + String indexName = "test_index_exists_index_present"; + createIndex(indexName, Settings.EMPTY); - public void testIndexExistsIfIndexNotPresent() throws IOException { - String indexName = "non_existent_index"; + GetIndexRequest request = new GetIndexRequest(); + request.indices(indexName); - GetIndexRequest request = new GetIndexRequest(); - request.indices(indexName); + boolean response = execute( + request, + highLevelClient().indices()::exists, + highLevelClient().indices()::existsAsync + ); + assertTrue(response); + } - boolean response = execute( - request, - highLevelClient().indices()::exists, - highLevelClient().indices()::existsAsync - ); - assertFalse(response); - } + // Index doesn't exist + { + String indexName = "non_existent_index"; - public void testIndexExistsIfOneIndexPresentOneIsnt() throws IOException { - String existingIndex = "test_index_exists_index_present"; - createIndex(existingIndex, Settings.EMPTY); + GetIndexRequest request = new GetIndexRequest(); + request.indices(indexName); - String nonExistentIndex = "non_existent_index"; + boolean response = execute( + request, + highLevelClient().indices()::exists, + highLevelClient().indices()::existsAsync + ); + assertFalse(response); + } + + // One index exists, one doesn't + { + String existingIndex = "apples"; + createIndex(existingIndex, Settings.EMPTY); - GetIndexRequest request = new GetIndexRequest(); - request.indices(existingIndex, nonExistentIndex); + String nonExistentIndex = "oranges"; + + GetIndexRequest request = new GetIndexRequest(); + request.indices(existingIndex, nonExistentIndex); + + boolean response = execute( + request, + highLevelClient().indices()::exists, + highLevelClient().indices()::existsAsync + ); + assertFalse(response); + } - boolean response = execute( - request, - highLevelClient().indices()::exists, - highLevelClient().indices()::existsAsync - ); - assertFalse(response); } @SuppressWarnings({"unchecked", "rawtypes"})