From b4c1c4a78cdaab678b1cc11fa1afa101591f3186 Mon Sep 17 00:00:00 2001 From: Luca Cavanna Date: Thu, 18 Jan 2018 11:57:24 +0100 Subject: [PATCH] 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. --- .../elasticsearch/client/IndicesClient.java | 16 +++++----- .../elasticsearch/client/IndicesClientIT.java | 26 ++++++++-------- .../IndicesClientDocumentationIT.java | 30 +++++++++---------- 3 files changed, 36 insertions(+), 36 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 4940267e85c22..2dd130fc6342e 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java @@ -51,7 +51,7 @@ public final class IndicesClient { * See * Delete Index API on elastic.co */ - public DeleteIndexResponse deleteIndex(DeleteIndexRequest deleteIndexRequest, Header... headers) throws IOException { + public DeleteIndexResponse delete(DeleteIndexRequest deleteIndexRequest, Header... headers) throws IOException { return restHighLevelClient.performRequestAndParseEntity(deleteIndexRequest, Request::deleteIndex, DeleteIndexResponse::fromXContent, Collections.emptySet(), headers); } @@ -62,7 +62,7 @@ public DeleteIndexResponse deleteIndex(DeleteIndexRequest deleteIndexRequest, He * See * Delete Index API on elastic.co */ - public void deleteIndexAsync(DeleteIndexRequest deleteIndexRequest, ActionListener listener, Header... headers) { + public void deleteAsync(DeleteIndexRequest deleteIndexRequest, ActionListener listener, Header... headers) { restHighLevelClient.performRequestAsyncAndParseEntity(deleteIndexRequest, Request::deleteIndex, DeleteIndexResponse::fromXContent, listener, Collections.emptySet(), headers); } @@ -73,7 +73,7 @@ public void deleteIndexAsync(DeleteIndexRequest deleteIndexRequest, ActionListen * See * Create Index API on elastic.co */ - public CreateIndexResponse createIndex(CreateIndexRequest createIndexRequest, Header... headers) throws IOException { + public CreateIndexResponse create(CreateIndexRequest createIndexRequest, Header... headers) throws IOException { return restHighLevelClient.performRequestAndParseEntity(createIndexRequest, Request::createIndex, CreateIndexResponse::fromXContent, Collections.emptySet(), headers); } @@ -84,7 +84,7 @@ public CreateIndexResponse createIndex(CreateIndexRequest createIndexRequest, He * See * Create Index API on elastic.co */ - public void createIndexAsync(CreateIndexRequest createIndexRequest, ActionListener listener, Header... headers) { + public void createAsync(CreateIndexRequest createIndexRequest, ActionListener listener, Header... headers) { restHighLevelClient.performRequestAsyncAndParseEntity(createIndexRequest, Request::createIndex, CreateIndexResponse::fromXContent, listener, Collections.emptySet(), headers); } @@ -95,7 +95,7 @@ public void createIndexAsync(CreateIndexRequest createIndexRequest, ActionListen * See * Open Index API on elastic.co */ - public OpenIndexResponse openIndex(OpenIndexRequest openIndexRequest, Header... headers) throws IOException { + public OpenIndexResponse open(OpenIndexRequest openIndexRequest, Header... headers) throws IOException { return restHighLevelClient.performRequestAndParseEntity(openIndexRequest, Request::openIndex, OpenIndexResponse::fromXContent, Collections.emptySet(), headers); } @@ -106,7 +106,7 @@ public OpenIndexResponse openIndex(OpenIndexRequest openIndexRequest, Header... * See * Open Index API on elastic.co */ - public void openIndexAsync(OpenIndexRequest openIndexRequest, ActionListener listener, Header... headers) { + public void openAsync(OpenIndexRequest openIndexRequest, ActionListener listener, Header... headers) { restHighLevelClient.performRequestAsyncAndParseEntity(openIndexRequest, Request::openIndex, OpenIndexResponse::fromXContent, listener, Collections.emptySet(), headers); } @@ -117,7 +117,7 @@ public void openIndexAsync(OpenIndexRequest openIndexRequest, ActionListener * Close Index API on elastic.co */ - public CloseIndexResponse closeIndex(CloseIndexRequest closeIndexRequest, Header... headers) throws IOException { + public CloseIndexResponse close(CloseIndexRequest closeIndexRequest, Header... headers) throws IOException { return restHighLevelClient.performRequestAndParseEntity(closeIndexRequest, Request::closeIndex, CloseIndexResponse::fromXContent, Collections.emptySet(), headers); } @@ -128,7 +128,7 @@ public CloseIndexResponse closeIndex(CloseIndexRequest closeIndexRequest, Header * See * Close Index API on elastic.co */ - public void closeIndexAsync(CloseIndexRequest closeIndexRequest, ActionListener listener, Header... headers) { + public void closeAsync(CloseIndexRequest closeIndexRequest, ActionListener listener, Header... headers) { restHighLevelClient.performRequestAsyncAndParseEntity(closeIndexRequest, Request::closeIndex, CloseIndexResponse::fromXContent, listener, Collections.emptySet(), headers); } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java index 361b60a5218cf..5f8702807fb30 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 testCreateIndex() throws IOException { CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName); CreateIndexResponse createIndexResponse = - execute(createIndexRequest, highLevelClient().indices()::createIndex, highLevelClient().indices()::createIndexAsync); + execute(createIndexRequest, highLevelClient().indices()::create, highLevelClient().indices()::createAsync); assertTrue(createIndexResponse.isAcknowledged()); assertTrue(indexExists(indexName)); @@ -83,7 +83,7 @@ public void testCreateIndex() throws IOException { createIndexRequest.mapping("type_name", mappingBuilder); CreateIndexResponse createIndexResponse = - execute(createIndexRequest, highLevelClient().indices()::createIndex, highLevelClient().indices()::createIndexAsync); + execute(createIndexRequest, highLevelClient().indices()::create, highLevelClient().indices()::createAsync); assertTrue(createIndexResponse.isAcknowledged()); Map indexMetaData = getIndexMetadata(indexName); @@ -116,7 +116,7 @@ public void testDeleteIndex() throws IOException { DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indexName); DeleteIndexResponse deleteIndexResponse = - execute(deleteIndexRequest, highLevelClient().indices()::deleteIndex, highLevelClient().indices()::deleteIndexAsync); + execute(deleteIndexRequest, highLevelClient().indices()::delete, highLevelClient().indices()::deleteAsync); assertTrue(deleteIndexResponse.isAcknowledged()); assertFalse(indexExists(indexName)); @@ -129,7 +129,7 @@ public void testDeleteIndex() throws IOException { DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(nonExistentIndex); ElasticsearchException exception = expectThrows(ElasticsearchException.class, - () -> execute(deleteIndexRequest, highLevelClient().indices()::deleteIndex, highLevelClient().indices()::deleteIndexAsync)); + () -> execute(deleteIndexRequest, highLevelClient().indices()::delete, highLevelClient().indices()::deleteAsync)); assertEquals(RestStatus.NOT_FOUND, exception.status()); } } @@ -143,8 +143,8 @@ public void testOpenExistingIndex() throws IOException { assertThat(exception.getMessage().contains(index), equalTo(true)); OpenIndexRequest openIndexRequest = new OpenIndexRequest(index); - OpenIndexResponse openIndexResponse = execute(openIndexRequest, highLevelClient().indices()::openIndex, - highLevelClient().indices()::openIndexAsync); + OpenIndexResponse openIndexResponse = execute(openIndexRequest, highLevelClient().indices()::open, + highLevelClient().indices()::openAsync); assertTrue(openIndexResponse.isAcknowledged()); Response response = client().performRequest("GET", index + "/_search"); @@ -157,19 +157,19 @@ public void testOpenNonExistentIndex() throws IOException { OpenIndexRequest openIndexRequest = new OpenIndexRequest(nonExistentIndex); ElasticsearchException exception = expectThrows(ElasticsearchException.class, - () -> execute(openIndexRequest, highLevelClient().indices()::openIndex, highLevelClient().indices()::openIndexAsync)); + () -> execute(openIndexRequest, highLevelClient().indices()::open, highLevelClient().indices()::openAsync)); assertEquals(RestStatus.NOT_FOUND, exception.status()); OpenIndexRequest lenientOpenIndexRequest = new OpenIndexRequest(nonExistentIndex); lenientOpenIndexRequest.indicesOptions(IndicesOptions.lenientExpandOpen()); - OpenIndexResponse lenientOpenIndexResponse = execute(lenientOpenIndexRequest, highLevelClient().indices()::openIndex, - highLevelClient().indices()::openIndexAsync); + OpenIndexResponse lenientOpenIndexResponse = execute(lenientOpenIndexRequest, highLevelClient().indices()::open, + highLevelClient().indices()::openAsync); assertThat(lenientOpenIndexResponse.isAcknowledged(), equalTo(true)); OpenIndexRequest strictOpenIndexRequest = new OpenIndexRequest(nonExistentIndex); strictOpenIndexRequest.indicesOptions(IndicesOptions.strictExpandOpen()); ElasticsearchException strictException = expectThrows(ElasticsearchException.class, - () -> execute(openIndexRequest, highLevelClient().indices()::openIndex, highLevelClient().indices()::openIndexAsync)); + () -> execute(openIndexRequest, highLevelClient().indices()::open, highLevelClient().indices()::openAsync)); assertEquals(RestStatus.NOT_FOUND, strictException.status()); } @@ -180,8 +180,8 @@ public void testCloseExistingIndex() throws IOException { assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus())); CloseIndexRequest closeIndexRequest = new CloseIndexRequest(index); - CloseIndexResponse closeIndexResponse = execute(closeIndexRequest, highLevelClient().indices()::closeIndex, - highLevelClient().indices()::closeIndexAsync); + CloseIndexResponse closeIndexResponse = execute(closeIndexRequest, highLevelClient().indices()::close, + highLevelClient().indices()::closeAsync); assertTrue(closeIndexResponse.isAcknowledged()); ResponseException exception = expectThrows(ResponseException.class, () -> client().performRequest("GET", index + "/_search")); @@ -195,7 +195,7 @@ public void testCloseNonExistentIndex() throws IOException { CloseIndexRequest closeIndexRequest = new CloseIndexRequest(nonExistentIndex); ElasticsearchException exception = expectThrows(ElasticsearchException.class, - () -> execute(closeIndexRequest, highLevelClient().indices()::closeIndex, highLevelClient().indices()::closeIndexAsync)); + () -> execute(closeIndexRequest, highLevelClient().indices()::close, highLevelClient().indices()::closeAsync)); assertEquals(RestStatus.NOT_FOUND, exception.status()); } 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 dd7e53eaa954c..bc3b1698f9679 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 @@ -62,7 +62,7 @@ public void testDeleteIndex() throws IOException { RestHighLevelClient client = highLevelClient(); { - CreateIndexResponse createIndexResponse = client.indices().createIndex(new CreateIndexRequest("posts")); + CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("posts")); assertTrue(createIndexResponse.isAcknowledged()); } @@ -84,7 +84,7 @@ public void testDeleteIndex() throws IOException { // end::delete-index-request-indicesOptions // tag::delete-index-execute - DeleteIndexResponse deleteIndexResponse = client.indices().deleteIndex(request); + DeleteIndexResponse deleteIndexResponse = client.indices().delete(request); // end::delete-index-execute // tag::delete-index-response @@ -97,7 +97,7 @@ public void testDeleteIndex() throws IOException { // tag::delete-index-notfound try { DeleteIndexRequest request = new DeleteIndexRequest("does_not_exist"); - client.indices().deleteIndex(request); + client.indices().delete(request); } catch (ElasticsearchException exception) { if (exception.status() == RestStatus.NOT_FOUND) { // <1> @@ -111,7 +111,7 @@ public void testDeleteIndexAsync() throws Exception { final RestHighLevelClient client = highLevelClient(); { - CreateIndexResponse createIndexResponse = client.indices().createIndex(new CreateIndexRequest("posts")); + CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("posts")); assertTrue(createIndexResponse.isAcknowledged()); } @@ -119,7 +119,7 @@ public void testDeleteIndexAsync() throws Exception { DeleteIndexRequest request = new DeleteIndexRequest("posts"); // tag::delete-index-execute-async - client.indices().deleteIndexAsync(request, new ActionListener() { + client.indices().deleteAsync(request, new ActionListener() { @Override public void onResponse(DeleteIndexResponse deleteIndexResponse) { // <1> @@ -189,7 +189,7 @@ public void testCreateIndex() throws IOException { // end::create-index-request-waitForActiveShards // tag::create-index-execute - CreateIndexResponse createIndexResponse = client.indices().createIndex(request); + CreateIndexResponse createIndexResponse = client.indices().create(request); // end::create-index-execute // tag::create-index-response @@ -207,7 +207,7 @@ public void testCreateIndexAsync() throws Exception { { CreateIndexRequest request = new CreateIndexRequest("twitter"); // tag::create-index-execute-async - client.indices().createIndexAsync(request, new ActionListener() { + client.indices().createAsync(request, new ActionListener() { @Override public void onResponse(CreateIndexResponse createIndexResponse) { // <1> @@ -232,7 +232,7 @@ public void testOpenIndex() throws IOException { RestHighLevelClient client = highLevelClient(); { - CreateIndexResponse createIndexResponse = client.indices().createIndex(new CreateIndexRequest("index")); + CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index")); assertTrue(createIndexResponse.isAcknowledged()); } @@ -260,7 +260,7 @@ public void testOpenIndex() throws IOException { // end::open-index-request-indicesOptions // tag::open-index-execute - OpenIndexResponse openIndexResponse = client.indices().openIndex(request); + OpenIndexResponse openIndexResponse = client.indices().open(request); // end::open-index-execute // tag::open-index-response @@ -271,7 +271,7 @@ public void testOpenIndex() throws IOException { assertTrue(shardsAcked); // tag::open-index-execute-async - client.indices().openIndexAsync(request, new ActionListener() { + client.indices().openAsync(request, new ActionListener() { @Override public void onResponse(OpenIndexResponse openIndexResponse) { // <1> @@ -289,7 +289,7 @@ public void onFailure(Exception e) { // tag::open-index-notfound try { OpenIndexRequest request = new OpenIndexRequest("does_not_exist"); - client.indices().openIndex(request); + client.indices().open(request); } catch (ElasticsearchException exception) { if (exception.status() == RestStatus.BAD_REQUEST) { // <1> @@ -303,7 +303,7 @@ public void testCloseIndex() throws IOException { RestHighLevelClient client = highLevelClient(); { - CreateIndexResponse createIndexResponse = client.indices().createIndex(new CreateIndexRequest("index")); + CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index")); assertTrue(createIndexResponse.isAcknowledged()); } @@ -326,7 +326,7 @@ public void testCloseIndex() throws IOException { // end::close-index-request-indicesOptions // tag::close-index-execute - CloseIndexResponse closeIndexResponse = client.indices().closeIndex(request); + CloseIndexResponse closeIndexResponse = client.indices().close(request); // end::close-index-execute // tag::close-index-response @@ -335,7 +335,7 @@ public void testCloseIndex() throws IOException { assertTrue(acknowledged); // tag::close-index-execute-async - client.indices().closeIndexAsync(request, new ActionListener() { + client.indices().closeAsync(request, new ActionListener() { @Override public void onResponse(CloseIndexResponse closeIndexResponse) { // <1> @@ -353,7 +353,7 @@ public void onFailure(Exception e) { // tag::close-index-notfound try { CloseIndexRequest request = new CloseIndexRequest("does_not_exist"); - client.indices().closeIndex(request); + client.indices().close(request); } catch (ElasticsearchException exception) { if (exception.status() == RestStatus.BAD_REQUEST) { // <1>