From e72cb7947654969cf6d141c1656f082dbac86fe2 Mon Sep 17 00:00:00 2001 From: Przemko Robakowski Date: Mon, 24 Feb 2020 18:22:09 +0100 Subject: [PATCH] Add docs for errors in GetAlias API (#51850) (#52716) Closes #31499 Co-authored-by: Maxim --- .../elasticsearch/client/IndicesClientIT.java | 15 +++++++++++++ .../IndicesClientDocumentationIT.java | 10 +++++++++ .../high-level/indices/get_alias.asciidoc | 22 ++++++++++++++++++- 3 files changed, 46 insertions(+), 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 c49720a9497..bc1e889713c 100644 --- 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 @@ -1382,6 +1382,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase { highLevelClient().indices()::getAliasAsync); assertThat(getAliasesResponse.status(), equalTo(RestStatus.NOT_FOUND)); assertThat(getAliasesResponse.getError(), equalTo("alias [" + alias + "] missing")); + assertThat(getAliasesResponse.getException(), nullValue()); } createIndex(index, Settings.EMPTY); client().performRequest(new Request(HttpPut.METHOD_NAME, index + "/_alias/" + alias)); @@ -1389,7 +1390,9 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase { GetAliasesRequest getAliasesRequest = new GetAliasesRequest().indices(index, "non_existent_index"); GetAliasesResponse getAliasesResponse = execute(getAliasesRequest, highLevelClient().indices()::getAlias, highLevelClient().indices()::getAliasAsync); + assertThat(getAliasesResponse.getAliases().size(), equalTo(0)); assertThat(getAliasesResponse.status(), equalTo(RestStatus.NOT_FOUND)); + assertThat(getAliasesResponse.getError(), nullValue()); assertThat(getAliasesResponse.getException().getMessage(), equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index [non_existent_index]]")); } @@ -1397,6 +1400,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase { GetAliasesRequest getAliasesRequest = new GetAliasesRequest().indices(index, "non_existent_index").aliases(alias); GetAliasesResponse getAliasesResponse = execute(getAliasesRequest, highLevelClient().indices()::getAlias, highLevelClient().indices()::getAliasAsync); + assertThat(getAliasesResponse.getAliases().size(), equalTo(0)); assertThat(getAliasesResponse.status(), equalTo(RestStatus.NOT_FOUND)); assertThat(getAliasesResponse.getException().getMessage(), equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index [non_existent_index]]")); @@ -1405,13 +1409,17 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase { GetAliasesRequest getAliasesRequest = new GetAliasesRequest().indices("non_existent_index*"); GetAliasesResponse getAliasesResponse = execute(getAliasesRequest, highLevelClient().indices()::getAlias, highLevelClient().indices()::getAliasAsync); + assertThat(getAliasesResponse.status(), equalTo(RestStatus.OK)); assertThat(getAliasesResponse.getAliases().size(), equalTo(0)); + assertThat(getAliasesResponse.getException(), nullValue()); + assertThat(getAliasesResponse.getError(), nullValue()); } { GetAliasesRequest getAliasesRequest = new GetAliasesRequest().indices(index).aliases(alias, "non_existent_alias"); GetAliasesResponse getAliasesResponse = execute(getAliasesRequest, highLevelClient().indices()::getAlias, highLevelClient().indices()::getAliasAsync); assertThat(getAliasesResponse.status(), equalTo(RestStatus.NOT_FOUND)); + assertThat(getAliasesResponse.getError(), equalTo("alias [non_existent_alias] missing")); assertThat(getAliasesResponse.getAliases().size(), equalTo(1)); assertThat(getAliasesResponse.getAliases().get(index).size(), equalTo(1)); @@ -1431,6 +1439,13 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase { } */ } + { + GetAliasesRequest getAliasesRequest = new GetAliasesRequest().aliases("non_existent_alias*"); + GetAliasesResponse getAliasesResponse = execute(getAliasesRequest, highLevelClient().indices()::getAlias, + highLevelClient().indices()::getAliasAsync); + assertThat(getAliasesResponse.status(), equalTo(RestStatus.OK)); + assertThat(getAliasesResponse.getAliases().size(), equalTo(0)); + } } public void testIndexPutSettings() throws IOException { 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 71beb2ad006..84dd36b198c 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 @@ -112,6 +112,7 @@ import java.util.concurrent.TimeUnit; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.nullValue; /** * This class is used to generate the Java Indices API documentation. @@ -2000,8 +2001,17 @@ public class IndicesClientDocumentationIT extends ESRestHighLevelClientTestCase Map> aliases = response.getAliases(); // <1> // end::get-alias-response + // tag::get-alias-response-error + RestStatus status = response.status(); // <1> + ElasticsearchException exception = response.getException(); // <2> + String error = response.getError(); // <3> + // end::get-alias-response-error + assertThat(response.getAliases().get("index").size(), equalTo(1)); assertThat(response.getAliases().get("index").iterator().next().alias(), equalTo("alias")); + assertThat(status, equalTo(RestStatus.OK)); + assertThat(error, nullValue()); + assertThat(exception, nullValue()); // tag::get-alias-execute-listener ActionListener listener = diff --git a/docs/java-rest/high-level/indices/get_alias.asciidoc b/docs/java-rest/high-level/indices/get_alias.asciidoc index f36591f33ac..c51f9fe5b95 100644 --- a/docs/java-rest/high-level/indices/get_alias.asciidoc +++ b/docs/java-rest/high-level/indices/get_alias.asciidoc @@ -62,4 +62,24 @@ executed operation as follows: -------------------------------------------------- include-tagged::{doc-tests-file}[{api}-response] -------------------------------------------------- -<1> Retrieves a map of indices and their aliases \ No newline at end of file +<1> Retrieves a map of indices and their aliases + ++{response}+ class contains information about errors if they occurred. +This info could be in fields `error` or `exception` depends on a case. + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests-file}[{api}-response-error] +-------------------------------------------------- +<1> Client sets status to `NOT_FOUND` if at least one item of specified +indices or aliases is not found. Otherwise it is `OK`. + +<2> If at least one item of specified indices isn't exist client sets +`ElasticsearchException` and returns empty result. + +<3> If at least one item of specified aliases ins't exist client puts +error description in `error` field and returns partial result if any +of other patterns match. + +If user specified indices or aliases as regular expressions +and nothing was found client returns `OK` status and no errors.