Skip to content

Commit 5dd27c1

Browse files
committed
Add docs for errors in GetAlias API
Closes #31499
1 parent 749b623 commit 5dd27c1

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,21 +1106,25 @@ public void testGetAliasesNonExistentIndexOrAlias() throws IOException {
11061106
highLevelClient().indices()::getAliasAsync);
11071107
assertThat(getAliasesResponse.status(), equalTo(RestStatus.NOT_FOUND));
11081108
assertThat(getAliasesResponse.getError(), equalTo("alias [" + alias + "] missing"));
1109+
assertThat(getAliasesResponse.getException(), nullValue());
11091110
}
11101111
createIndex(index, Settings.EMPTY);
11111112
client().performRequest(new Request(HttpPut.METHOD_NAME, index + "/_alias/" + alias));
11121113
{
11131114
GetAliasesRequest getAliasesRequest = new GetAliasesRequest().indices(index, "non_existent_index");
11141115
GetAliasesResponse getAliasesResponse = execute(getAliasesRequest, highLevelClient().indices()::getAlias,
11151116
highLevelClient().indices()::getAliasAsync);
1117+
assertThat(getAliasesResponse.getAliases().size(), equalTo(0));
11161118
assertThat(getAliasesResponse.status(), equalTo(RestStatus.NOT_FOUND));
1119+
assertThat(getAliasesResponse.getError(), nullValue());
11171120
assertThat(getAliasesResponse.getException().getMessage(),
11181121
equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index [non_existent_index]]"));
11191122
}
11201123
{
11211124
GetAliasesRequest getAliasesRequest = new GetAliasesRequest().indices(index, "non_existent_index").aliases(alias);
11221125
GetAliasesResponse getAliasesResponse = execute(getAliasesRequest, highLevelClient().indices()::getAlias,
11231126
highLevelClient().indices()::getAliasAsync);
1127+
assertThat(getAliasesResponse.getAliases().size(), equalTo(0));
11241128
assertThat(getAliasesResponse.status(), equalTo(RestStatus.NOT_FOUND));
11251129
assertThat(getAliasesResponse.getException().getMessage(),
11261130
equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index [non_existent_index]]"));
@@ -1129,13 +1133,17 @@ public void testGetAliasesNonExistentIndexOrAlias() throws IOException {
11291133
GetAliasesRequest getAliasesRequest = new GetAliasesRequest().indices("non_existent_index*");
11301134
GetAliasesResponse getAliasesResponse = execute(getAliasesRequest, highLevelClient().indices()::getAlias,
11311135
highLevelClient().indices()::getAliasAsync);
1136+
assertThat(getAliasesResponse.status(), equalTo(RestStatus.OK));
11321137
assertThat(getAliasesResponse.getAliases().size(), equalTo(0));
1138+
assertThat(getAliasesResponse.getException(), nullValue());
1139+
assertThat(getAliasesResponse.getError(), nullValue());
11331140
}
11341141
{
11351142
GetAliasesRequest getAliasesRequest = new GetAliasesRequest().indices(index).aliases(alias, "non_existent_alias");
11361143
GetAliasesResponse getAliasesResponse = execute(getAliasesRequest, highLevelClient().indices()::getAlias,
11371144
highLevelClient().indices()::getAliasAsync);
11381145
assertThat(getAliasesResponse.status(), equalTo(RestStatus.NOT_FOUND));
1146+
assertThat(getAliasesResponse.getError(), equalTo("alias [non_existent_alias] missing"));
11391147

11401148
assertThat(getAliasesResponse.getAliases().size(), equalTo(1));
11411149
assertThat(getAliasesResponse.getAliases().get(index).size(), equalTo(1));
@@ -1155,6 +1163,13 @@ public void testGetAliasesNonExistentIndexOrAlias() throws IOException {
11551163
}
11561164
*/
11571165
}
1166+
{
1167+
GetAliasesRequest getAliasesRequest = new GetAliasesRequest().aliases("non_existent_alias*");
1168+
GetAliasesResponse getAliasesResponse = execute(getAliasesRequest, highLevelClient().indices()::getAlias,
1169+
highLevelClient().indices()::getAliasAsync);
1170+
assertThat(getAliasesResponse.status(), equalTo(RestStatus.OK));
1171+
assertThat(getAliasesResponse.getAliases().size(), equalTo(0));
1172+
}
11581173
}
11591174

11601175
public void testIndexPutSettings() throws IOException {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109

110110
import static org.hamcrest.Matchers.equalTo;
111111
import static org.hamcrest.Matchers.hasSize;
112+
import static org.hamcrest.Matchers.nullValue;
112113

113114
/**
114115
* This class is used to generate the Java Indices API documentation.
@@ -1909,8 +1910,17 @@ public void testGetAlias() throws Exception {
19091910
Map<String, Set<AliasMetaData>> aliases = response.getAliases(); // <1>
19101911
// end::get-alias-response
19111912

1913+
// tag::get-alias-response-error
1914+
RestStatus status = response.status(); // <1>
1915+
ElasticsearchException exception = response.getException(); // <2>
1916+
String error = response.getError(); // <3>
1917+
// end::get-alias-response-error
1918+
19121919
assertThat(response.getAliases().get("index").size(), equalTo(1));
19131920
assertThat(response.getAliases().get("index").iterator().next().alias(), equalTo("alias"));
1921+
assertThat(status, equalTo(RestStatus.OK));
1922+
assertThat(error, nullValue());
1923+
assertThat(exception, nullValue());
19141924

19151925
// tag::get-alias-execute-listener
19161926
ActionListener<GetAliasesResponse> listener =

docs/java-rest/high-level/indices/get_alias.asciidoc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,24 @@ executed operation as follows:
6262
--------------------------------------------------
6363
include-tagged::{doc-tests-file}[{api}-response]
6464
--------------------------------------------------
65-
<1> Retrieves a map of indices and their aliases
65+
<1> Retrieves a map of indices and their aliases
66+
67+
+{response}+ class contains information about errors if they occurred.
68+
This info could be in fields `error` or `exception` depends on a case.
69+
70+
["source","java",subs="attributes,callouts,macros"]
71+
--------------------------------------------------
72+
include-tagged::{doc-tests-file}[{api}-response-error]
73+
--------------------------------------------------
74+
<1> Client sets status to `NOT_FOUND` if at least one item of specified
75+
indices or aliases is not found. Otherwise it is `OK`.
76+
77+
<2> If at least one item of specified indices isn't exist client sets
78+
`ElasticsearchException` and returns empty result.
79+
80+
<3> If at least one item of specified aliases ins't exist client puts
81+
error description in `error` field and returns partial result if any
82+
of other patterns match.
83+
84+
If user specified indices or aliases as regular expressions
85+
and nothing was found client returns `OK` status and no errors.

0 commit comments

Comments
 (0)