Skip to content

Commit b4c1c4a

Browse files
authored
REST high-level client: remove index suffix from indices client method names (#28263)
Today, the way to call them API under the indices namespace is by doing e.g. `client.indices().createIndex()`. Our spec define the API under the indices namespace as e.g. `indices.create`, hence there is no need to repeat the index suffix for each method as that is already defined by the namespace. Using the `index` suffix in each method was an oversight which must be corrected.
1 parent c38c12e commit b4c1c4a

File tree

3 files changed

+36
-36
lines changed

3 files changed

+36
-36
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public final class IndicesClient {
5151
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html">
5252
* Delete Index API on elastic.co</a>
5353
*/
54-
public DeleteIndexResponse deleteIndex(DeleteIndexRequest deleteIndexRequest, Header... headers) throws IOException {
54+
public DeleteIndexResponse delete(DeleteIndexRequest deleteIndexRequest, Header... headers) throws IOException {
5555
return restHighLevelClient.performRequestAndParseEntity(deleteIndexRequest, Request::deleteIndex, DeleteIndexResponse::fromXContent,
5656
Collections.emptySet(), headers);
5757
}
@@ -62,7 +62,7 @@ public DeleteIndexResponse deleteIndex(DeleteIndexRequest deleteIndexRequest, He
6262
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html">
6363
* Delete Index API on elastic.co</a>
6464
*/
65-
public void deleteIndexAsync(DeleteIndexRequest deleteIndexRequest, ActionListener<DeleteIndexResponse> listener, Header... headers) {
65+
public void deleteAsync(DeleteIndexRequest deleteIndexRequest, ActionListener<DeleteIndexResponse> listener, Header... headers) {
6666
restHighLevelClient.performRequestAsyncAndParseEntity(deleteIndexRequest, Request::deleteIndex, DeleteIndexResponse::fromXContent,
6767
listener, Collections.emptySet(), headers);
6868
}
@@ -73,7 +73,7 @@ public void deleteIndexAsync(DeleteIndexRequest deleteIndexRequest, ActionListen
7373
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html">
7474
* Create Index API on elastic.co</a>
7575
*/
76-
public CreateIndexResponse createIndex(CreateIndexRequest createIndexRequest, Header... headers) throws IOException {
76+
public CreateIndexResponse create(CreateIndexRequest createIndexRequest, Header... headers) throws IOException {
7777
return restHighLevelClient.performRequestAndParseEntity(createIndexRequest, Request::createIndex, CreateIndexResponse::fromXContent,
7878
Collections.emptySet(), headers);
7979
}
@@ -84,7 +84,7 @@ public CreateIndexResponse createIndex(CreateIndexRequest createIndexRequest, He
8484
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html">
8585
* Create Index API on elastic.co</a>
8686
*/
87-
public void createIndexAsync(CreateIndexRequest createIndexRequest, ActionListener<CreateIndexResponse> listener, Header... headers) {
87+
public void createAsync(CreateIndexRequest createIndexRequest, ActionListener<CreateIndexResponse> listener, Header... headers) {
8888
restHighLevelClient.performRequestAsyncAndParseEntity(createIndexRequest, Request::createIndex, CreateIndexResponse::fromXContent,
8989
listener, Collections.emptySet(), headers);
9090
}
@@ -95,7 +95,7 @@ public void createIndexAsync(CreateIndexRequest createIndexRequest, ActionListen
9595
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html">
9696
* Open Index API on elastic.co</a>
9797
*/
98-
public OpenIndexResponse openIndex(OpenIndexRequest openIndexRequest, Header... headers) throws IOException {
98+
public OpenIndexResponse open(OpenIndexRequest openIndexRequest, Header... headers) throws IOException {
9999
return restHighLevelClient.performRequestAndParseEntity(openIndexRequest, Request::openIndex, OpenIndexResponse::fromXContent,
100100
Collections.emptySet(), headers);
101101
}
@@ -106,7 +106,7 @@ public OpenIndexResponse openIndex(OpenIndexRequest openIndexRequest, Header...
106106
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html">
107107
* Open Index API on elastic.co</a>
108108
*/
109-
public void openIndexAsync(OpenIndexRequest openIndexRequest, ActionListener<OpenIndexResponse> listener, Header... headers) {
109+
public void openAsync(OpenIndexRequest openIndexRequest, ActionListener<OpenIndexResponse> listener, Header... headers) {
110110
restHighLevelClient.performRequestAsyncAndParseEntity(openIndexRequest, Request::openIndex, OpenIndexResponse::fromXContent,
111111
listener, Collections.emptySet(), headers);
112112
}
@@ -117,7 +117,7 @@ public void openIndexAsync(OpenIndexRequest openIndexRequest, ActionListener<Ope
117117
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html">
118118
* Close Index API on elastic.co</a>
119119
*/
120-
public CloseIndexResponse closeIndex(CloseIndexRequest closeIndexRequest, Header... headers) throws IOException {
120+
public CloseIndexResponse close(CloseIndexRequest closeIndexRequest, Header... headers) throws IOException {
121121
return restHighLevelClient.performRequestAndParseEntity(closeIndexRequest, Request::closeIndex, CloseIndexResponse::fromXContent,
122122
Collections.emptySet(), headers);
123123
}
@@ -128,7 +128,7 @@ public CloseIndexResponse closeIndex(CloseIndexRequest closeIndexRequest, Header
128128
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html">
129129
* Close Index API on elastic.co</a>
130130
*/
131-
public void closeIndexAsync(CloseIndexRequest closeIndexRequest, ActionListener<CloseIndexResponse> listener, Header... headers) {
131+
public void closeAsync(CloseIndexRequest closeIndexRequest, ActionListener<CloseIndexResponse> listener, Header... headers) {
132132
restHighLevelClient.performRequestAsyncAndParseEntity(closeIndexRequest, Request::closeIndex, CloseIndexResponse::fromXContent,
133133
listener, Collections.emptySet(), headers);
134134
}

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void testCreateIndex() throws IOException {
5555
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
5656

5757
CreateIndexResponse createIndexResponse =
58-
execute(createIndexRequest, highLevelClient().indices()::createIndex, highLevelClient().indices()::createIndexAsync);
58+
execute(createIndexRequest, highLevelClient().indices()::create, highLevelClient().indices()::createAsync);
5959
assertTrue(createIndexResponse.isAcknowledged());
6060

6161
assertTrue(indexExists(indexName));
@@ -83,7 +83,7 @@ public void testCreateIndex() throws IOException {
8383
createIndexRequest.mapping("type_name", mappingBuilder);
8484

8585
CreateIndexResponse createIndexResponse =
86-
execute(createIndexRequest, highLevelClient().indices()::createIndex, highLevelClient().indices()::createIndexAsync);
86+
execute(createIndexRequest, highLevelClient().indices()::create, highLevelClient().indices()::createAsync);
8787
assertTrue(createIndexResponse.isAcknowledged());
8888

8989
Map<String, Object> indexMetaData = getIndexMetadata(indexName);
@@ -116,7 +116,7 @@ public void testDeleteIndex() throws IOException {
116116

117117
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indexName);
118118
DeleteIndexResponse deleteIndexResponse =
119-
execute(deleteIndexRequest, highLevelClient().indices()::deleteIndex, highLevelClient().indices()::deleteIndexAsync);
119+
execute(deleteIndexRequest, highLevelClient().indices()::delete, highLevelClient().indices()::deleteAsync);
120120
assertTrue(deleteIndexResponse.isAcknowledged());
121121

122122
assertFalse(indexExists(indexName));
@@ -129,7 +129,7 @@ public void testDeleteIndex() throws IOException {
129129
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(nonExistentIndex);
130130

131131
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
132-
() -> execute(deleteIndexRequest, highLevelClient().indices()::deleteIndex, highLevelClient().indices()::deleteIndexAsync));
132+
() -> execute(deleteIndexRequest, highLevelClient().indices()::delete, highLevelClient().indices()::deleteAsync));
133133
assertEquals(RestStatus.NOT_FOUND, exception.status());
134134
}
135135
}
@@ -143,8 +143,8 @@ public void testOpenExistingIndex() throws IOException {
143143
assertThat(exception.getMessage().contains(index), equalTo(true));
144144

145145
OpenIndexRequest openIndexRequest = new OpenIndexRequest(index);
146-
OpenIndexResponse openIndexResponse = execute(openIndexRequest, highLevelClient().indices()::openIndex,
147-
highLevelClient().indices()::openIndexAsync);
146+
OpenIndexResponse openIndexResponse = execute(openIndexRequest, highLevelClient().indices()::open,
147+
highLevelClient().indices()::openAsync);
148148
assertTrue(openIndexResponse.isAcknowledged());
149149

150150
Response response = client().performRequest("GET", index + "/_search");
@@ -157,19 +157,19 @@ public void testOpenNonExistentIndex() throws IOException {
157157

158158
OpenIndexRequest openIndexRequest = new OpenIndexRequest(nonExistentIndex);
159159
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
160-
() -> execute(openIndexRequest, highLevelClient().indices()::openIndex, highLevelClient().indices()::openIndexAsync));
160+
() -> execute(openIndexRequest, highLevelClient().indices()::open, highLevelClient().indices()::openAsync));
161161
assertEquals(RestStatus.NOT_FOUND, exception.status());
162162

163163
OpenIndexRequest lenientOpenIndexRequest = new OpenIndexRequest(nonExistentIndex);
164164
lenientOpenIndexRequest.indicesOptions(IndicesOptions.lenientExpandOpen());
165-
OpenIndexResponse lenientOpenIndexResponse = execute(lenientOpenIndexRequest, highLevelClient().indices()::openIndex,
166-
highLevelClient().indices()::openIndexAsync);
165+
OpenIndexResponse lenientOpenIndexResponse = execute(lenientOpenIndexRequest, highLevelClient().indices()::open,
166+
highLevelClient().indices()::openAsync);
167167
assertThat(lenientOpenIndexResponse.isAcknowledged(), equalTo(true));
168168

169169
OpenIndexRequest strictOpenIndexRequest = new OpenIndexRequest(nonExistentIndex);
170170
strictOpenIndexRequest.indicesOptions(IndicesOptions.strictExpandOpen());
171171
ElasticsearchException strictException = expectThrows(ElasticsearchException.class,
172-
() -> execute(openIndexRequest, highLevelClient().indices()::openIndex, highLevelClient().indices()::openIndexAsync));
172+
() -> execute(openIndexRequest, highLevelClient().indices()::open, highLevelClient().indices()::openAsync));
173173
assertEquals(RestStatus.NOT_FOUND, strictException.status());
174174
}
175175

@@ -180,8 +180,8 @@ public void testCloseExistingIndex() throws IOException {
180180
assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus()));
181181

182182
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(index);
183-
CloseIndexResponse closeIndexResponse = execute(closeIndexRequest, highLevelClient().indices()::closeIndex,
184-
highLevelClient().indices()::closeIndexAsync);
183+
CloseIndexResponse closeIndexResponse = execute(closeIndexRequest, highLevelClient().indices()::close,
184+
highLevelClient().indices()::closeAsync);
185185
assertTrue(closeIndexResponse.isAcknowledged());
186186

187187
ResponseException exception = expectThrows(ResponseException.class, () -> client().performRequest("GET", index + "/_search"));
@@ -195,7 +195,7 @@ public void testCloseNonExistentIndex() throws IOException {
195195

196196
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(nonExistentIndex);
197197
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
198-
() -> execute(closeIndexRequest, highLevelClient().indices()::closeIndex, highLevelClient().indices()::closeIndexAsync));
198+
() -> execute(closeIndexRequest, highLevelClient().indices()::close, highLevelClient().indices()::closeAsync));
199199
assertEquals(RestStatus.NOT_FOUND, exception.status());
200200
}
201201

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void testDeleteIndex() throws IOException {
6262
RestHighLevelClient client = highLevelClient();
6363

6464
{
65-
CreateIndexResponse createIndexResponse = client.indices().createIndex(new CreateIndexRequest("posts"));
65+
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("posts"));
6666
assertTrue(createIndexResponse.isAcknowledged());
6767
}
6868

@@ -84,7 +84,7 @@ public void testDeleteIndex() throws IOException {
8484
// end::delete-index-request-indicesOptions
8585

8686
// tag::delete-index-execute
87-
DeleteIndexResponse deleteIndexResponse = client.indices().deleteIndex(request);
87+
DeleteIndexResponse deleteIndexResponse = client.indices().delete(request);
8888
// end::delete-index-execute
8989

9090
// tag::delete-index-response
@@ -97,7 +97,7 @@ public void testDeleteIndex() throws IOException {
9797
// tag::delete-index-notfound
9898
try {
9999
DeleteIndexRequest request = new DeleteIndexRequest("does_not_exist");
100-
client.indices().deleteIndex(request);
100+
client.indices().delete(request);
101101
} catch (ElasticsearchException exception) {
102102
if (exception.status() == RestStatus.NOT_FOUND) {
103103
// <1>
@@ -111,15 +111,15 @@ public void testDeleteIndexAsync() throws Exception {
111111
final RestHighLevelClient client = highLevelClient();
112112

113113
{
114-
CreateIndexResponse createIndexResponse = client.indices().createIndex(new CreateIndexRequest("posts"));
114+
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("posts"));
115115
assertTrue(createIndexResponse.isAcknowledged());
116116
}
117117

118118
{
119119
DeleteIndexRequest request = new DeleteIndexRequest("posts");
120120

121121
// tag::delete-index-execute-async
122-
client.indices().deleteIndexAsync(request, new ActionListener<DeleteIndexResponse>() {
122+
client.indices().deleteAsync(request, new ActionListener<DeleteIndexResponse>() {
123123
@Override
124124
public void onResponse(DeleteIndexResponse deleteIndexResponse) {
125125
// <1>
@@ -189,7 +189,7 @@ public void testCreateIndex() throws IOException {
189189
// end::create-index-request-waitForActiveShards
190190

191191
// tag::create-index-execute
192-
CreateIndexResponse createIndexResponse = client.indices().createIndex(request);
192+
CreateIndexResponse createIndexResponse = client.indices().create(request);
193193
// end::create-index-execute
194194

195195
// tag::create-index-response
@@ -207,7 +207,7 @@ public void testCreateIndexAsync() throws Exception {
207207
{
208208
CreateIndexRequest request = new CreateIndexRequest("twitter");
209209
// tag::create-index-execute-async
210-
client.indices().createIndexAsync(request, new ActionListener<CreateIndexResponse>() {
210+
client.indices().createAsync(request, new ActionListener<CreateIndexResponse>() {
211211
@Override
212212
public void onResponse(CreateIndexResponse createIndexResponse) {
213213
// <1>
@@ -232,7 +232,7 @@ public void testOpenIndex() throws IOException {
232232
RestHighLevelClient client = highLevelClient();
233233

234234
{
235-
CreateIndexResponse createIndexResponse = client.indices().createIndex(new CreateIndexRequest("index"));
235+
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"));
236236
assertTrue(createIndexResponse.isAcknowledged());
237237
}
238238

@@ -260,7 +260,7 @@ public void testOpenIndex() throws IOException {
260260
// end::open-index-request-indicesOptions
261261

262262
// tag::open-index-execute
263-
OpenIndexResponse openIndexResponse = client.indices().openIndex(request);
263+
OpenIndexResponse openIndexResponse = client.indices().open(request);
264264
// end::open-index-execute
265265

266266
// tag::open-index-response
@@ -271,7 +271,7 @@ public void testOpenIndex() throws IOException {
271271
assertTrue(shardsAcked);
272272

273273
// tag::open-index-execute-async
274-
client.indices().openIndexAsync(request, new ActionListener<OpenIndexResponse>() {
274+
client.indices().openAsync(request, new ActionListener<OpenIndexResponse>() {
275275
@Override
276276
public void onResponse(OpenIndexResponse openIndexResponse) {
277277
// <1>
@@ -289,7 +289,7 @@ public void onFailure(Exception e) {
289289
// tag::open-index-notfound
290290
try {
291291
OpenIndexRequest request = new OpenIndexRequest("does_not_exist");
292-
client.indices().openIndex(request);
292+
client.indices().open(request);
293293
} catch (ElasticsearchException exception) {
294294
if (exception.status() == RestStatus.BAD_REQUEST) {
295295
// <1>
@@ -303,7 +303,7 @@ public void testCloseIndex() throws IOException {
303303
RestHighLevelClient client = highLevelClient();
304304

305305
{
306-
CreateIndexResponse createIndexResponse = client.indices().createIndex(new CreateIndexRequest("index"));
306+
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"));
307307
assertTrue(createIndexResponse.isAcknowledged());
308308
}
309309

@@ -326,7 +326,7 @@ public void testCloseIndex() throws IOException {
326326
// end::close-index-request-indicesOptions
327327

328328
// tag::close-index-execute
329-
CloseIndexResponse closeIndexResponse = client.indices().closeIndex(request);
329+
CloseIndexResponse closeIndexResponse = client.indices().close(request);
330330
// end::close-index-execute
331331

332332
// tag::close-index-response
@@ -335,7 +335,7 @@ public void testCloseIndex() throws IOException {
335335
assertTrue(acknowledged);
336336

337337
// tag::close-index-execute-async
338-
client.indices().closeIndexAsync(request, new ActionListener<CloseIndexResponse>() {
338+
client.indices().closeAsync(request, new ActionListener<CloseIndexResponse>() {
339339
@Override
340340
public void onResponse(CloseIndexResponse closeIndexResponse) {
341341
// <1>
@@ -353,7 +353,7 @@ public void onFailure(Exception e) {
353353
// tag::close-index-notfound
354354
try {
355355
CloseIndexRequest request = new CloseIndexRequest("does_not_exist");
356-
client.indices().closeIndex(request);
356+
client.indices().close(request);
357357
} catch (ElasticsearchException exception) {
358358
if (exception.status() == RestStatus.BAD_REQUEST) {
359359
// <1>

0 commit comments

Comments
 (0)