Skip to content

Commit

Permalink
REST high-level client: remove index suffix from indices client metho…
Browse files Browse the repository at this point in the history
…d 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.
  • Loading branch information
javanna committed Jan 18, 2018
1 parent d486708 commit b6ebebc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public final class IndicesClient {
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html">
* Delete Index API on elastic.co</a>
*/
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);
}
Expand All @@ -62,7 +62,7 @@ public DeleteIndexResponse deleteIndex(DeleteIndexRequest deleteIndexRequest, He
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html">
* Delete Index API on elastic.co</a>
*/
public void deleteIndexAsync(DeleteIndexRequest deleteIndexRequest, ActionListener<DeleteIndexResponse> listener, Header... headers) {
public void deleteAsync(DeleteIndexRequest deleteIndexRequest, ActionListener<DeleteIndexResponse> listener, Header... headers) {
restHighLevelClient.performRequestAsyncAndParseEntity(deleteIndexRequest, Request::deleteIndex, DeleteIndexResponse::fromXContent,
listener, Collections.emptySet(), headers);
}
Expand All @@ -73,7 +73,7 @@ public void deleteIndexAsync(DeleteIndexRequest deleteIndexRequest, ActionListen
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html">
* Create Index API on elastic.co</a>
*/
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);
}
Expand All @@ -84,7 +84,7 @@ public CreateIndexResponse createIndex(CreateIndexRequest createIndexRequest, He
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html">
* Create Index API on elastic.co</a>
*/
public void createIndexAsync(CreateIndexRequest createIndexRequest, ActionListener<CreateIndexResponse> listener, Header... headers) {
public void createAsync(CreateIndexRequest createIndexRequest, ActionListener<CreateIndexResponse> listener, Header... headers) {
restHighLevelClient.performRequestAsyncAndParseEntity(createIndexRequest, Request::createIndex, CreateIndexResponse::fromXContent,
listener, Collections.emptySet(), headers);
}
Expand All @@ -95,7 +95,7 @@ public void createIndexAsync(CreateIndexRequest createIndexRequest, ActionListen
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html">
* Open Index API on elastic.co</a>
*/
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);
}
Expand All @@ -106,7 +106,7 @@ public OpenIndexResponse openIndex(OpenIndexRequest openIndexRequest, Header...
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html">
* Open Index API on elastic.co</a>
*/
public void openIndexAsync(OpenIndexRequest openIndexRequest, ActionListener<OpenIndexResponse> listener, Header... headers) {
public void openAsync(OpenIndexRequest openIndexRequest, ActionListener<OpenIndexResponse> listener, Header... headers) {
restHighLevelClient.performRequestAsyncAndParseEntity(openIndexRequest, Request::openIndex, OpenIndexResponse::fromXContent,
listener, Collections.emptySet(), headers);
}
Expand All @@ -117,7 +117,7 @@ public void openIndexAsync(OpenIndexRequest openIndexRequest, ActionListener<Ope
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html">
* Close Index API on elastic.co</a>
*/
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);
}
Expand All @@ -128,7 +128,7 @@ public CloseIndexResponse closeIndex(CloseIndexRequest closeIndexRequest, Header
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html">
* Close Index API on elastic.co</a>
*/
public void closeIndexAsync(CloseIndexRequest closeIndexRequest, ActionListener<CloseIndexResponse> listener, Header... headers) {
public void closeAsync(CloseIndexRequest closeIndexRequest, ActionListener<CloseIndexResponse> listener, Header... headers) {
restHighLevelClient.performRequestAsyncAndParseEntity(closeIndexRequest, Request::closeIndex, CloseIndexResponse::fromXContent,
listener, Collections.emptySet(), headers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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));
Expand Down Expand Up @@ -84,7 +84,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<String, Object> indexMetaData = getIndexMetadata(indexName);
Expand Down Expand Up @@ -117,7 +117,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));
Expand All @@ -130,7 +130,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());
}
}
Expand All @@ -144,8 +144,8 @@ public void testOpenExistingIndex() throws IOException {
assertThat(exception.getMessage().contains(index), equalTo(true));

OpenIndexRequest openIndexRequest = new OpenIndexRequest(index).waitForActiveShards(ActiveShardCount.ONE);
OpenIndexResponse openIndexResponse = execute(openIndexRequest, highLevelClient().indices()::openIndex,
highLevelClient().indices()::openIndexAsync);
OpenIndexResponse openIndexResponse = execute(openIndexRequest, highLevelClient().indices()::open,
highLevelClient().indices()::openAsync);
assertTrue(openIndexResponse.isAcknowledged());
assertTrue(openIndexResponse.isShardsAcknowledged());

Expand All @@ -159,19 +159,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());
}

Expand All @@ -182,8 +182,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"));
Expand All @@ -197,7 +197,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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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
Expand All @@ -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>
Expand All @@ -111,15 +111,15 @@ 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());
}

{
DeleteIndexRequest request = new DeleteIndexRequest("posts");

// tag::delete-index-execute-async
client.indices().deleteIndexAsync(request, new ActionListener<DeleteIndexResponse>() {
client.indices().deleteAsync(request, new ActionListener<DeleteIndexResponse>() {
@Override
public void onResponse(DeleteIndexResponse deleteIndexResponse) {
// <1>
Expand Down Expand Up @@ -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
Expand All @@ -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<CreateIndexResponse>() {
client.indices().createAsync(request, new ActionListener<CreateIndexResponse>() {
@Override
public void onResponse(CreateIndexResponse createIndexResponse) {
// <1>
Expand All @@ -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());
}

Expand Down Expand Up @@ -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
Expand All @@ -271,7 +271,7 @@ public void testOpenIndex() throws IOException {
assertTrue(shardsAcked);

// tag::open-index-execute-async
client.indices().openIndexAsync(request, new ActionListener<OpenIndexResponse>() {
client.indices().openAsync(request, new ActionListener<OpenIndexResponse>() {
@Override
public void onResponse(OpenIndexResponse openIndexResponse) {
// <1>
Expand All @@ -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>
Expand All @@ -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());
}

Expand All @@ -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
Expand All @@ -335,7 +335,7 @@ public void testCloseIndex() throws IOException {
assertTrue(acknowledged);

// tag::close-index-execute-async
client.indices().closeIndexAsync(request, new ActionListener<CloseIndexResponse>() {
client.indices().closeAsync(request, new ActionListener<CloseIndexResponse>() {
@Override
public void onResponse(CloseIndexResponse closeIndexResponse) {
// <1>
Expand All @@ -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>
Expand Down

0 comments on commit b6ebebc

Please sign in to comment.