-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Added Delete Index support to high-level REST client #27019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
javanna
merged 14 commits into
elastic:master
from
catalin-ursachi:25847-delete-index-hlrc
Oct 26, 2017
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e0345a8
Added Delete Index support to high-level REST client
catalin-ursachi 1540e93
Fixed code style
catalin-ursachi c8e35a6
Fixed remaining checkstyle errors
catalin-ursachi 77a9939
Review mark-ups
catalin-ursachi a18662f
Exctracted IndicesClient from RestHighLevelClient;
catalin-ursachi a03b759
Fixed typos
catalin-ursachi 30319ea
Added Delete Index docs
catalin-ursachi 7261ac9
Added Delete Index docs; review mark-ups
catalin-ursachi 1fe19fe
Use lambdas in RequestTests
catalin-ursachi ec05d37
Mark-ups
catalin-ursachi 63ba5b5
Simplify lambda
catalin-ursachi afdcb40
Simplified lambda
catalin-ursachi c8620a9
Deleted redundant type parameter
catalin-ursachi dda2d39
Merge remote-tracking branch 'origin/master' into 25847-delete-index-…
catalin-ursachi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.client; | ||
|
|
||
| import org.apache.http.Header; | ||
| import org.elasticsearch.action.ActionListener; | ||
| import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; | ||
| import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collections; | ||
|
|
||
| /** | ||
| * A wrapper for the {@link RestHighLevelClient} that provides methods for accessing the Indices API. | ||
| * | ||
| * See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices.html">Indices API on elastic.co</a> | ||
| */ | ||
| public final class IndicesClient { | ||
| private final RestHighLevelClient restHighLevelClient; | ||
|
|
||
| public IndicesClient(RestHighLevelClient restHighLevelClient) { | ||
| this.restHighLevelClient = restHighLevelClient; | ||
| } | ||
|
|
||
| /** | ||
| * Deletes an index using the Delete Index API | ||
| * <p> | ||
| * 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 { | ||
| return restHighLevelClient.performRequestAndParseEntity(deleteIndexRequest, Request::deleteIndex, DeleteIndexResponse::fromXContent, | ||
| Collections.emptySet(), headers); | ||
| } | ||
|
|
||
| /** | ||
| * Asynchronously deletes an index using the Delete Index API | ||
| * <p> | ||
| * 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) { | ||
| restHighLevelClient.performRequestAsyncAndParseEntity(deleteIndexRequest, Request::deleteIndex, DeleteIndexResponse::fromXContent, | ||
| listener, Collections.emptySet(), headers); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.client; | ||
|
|
||
| import org.elasticsearch.ElasticsearchException; | ||
| import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; | ||
| import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse; | ||
| import org.elasticsearch.rest.RestStatus; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class IndicesClientIT extends ESRestHighLevelClientTestCase { | ||
|
|
||
| public void testDeleteIndex() throws IOException { | ||
| { | ||
| // Delete index if exists | ||
| String indexName = "test_index"; | ||
| createIndex(indexName); | ||
|
|
||
| DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indexName); | ||
| DeleteIndexResponse deleteIndexResponse = | ||
| execute(deleteIndexRequest, highLevelClient().indices()::deleteIndex, highLevelClient().indices()::deleteIndexAsync); | ||
| assertTrue(deleteIndexResponse.isAcknowledged()); | ||
|
|
||
| assertFalse(indexExists(indexName)); | ||
| } | ||
| { | ||
| // Return 404 if index doesn't exist | ||
| String nonExistentIndex = "non_existent_index"; | ||
| assertFalse(indexExists(nonExistentIndex)); | ||
|
|
||
| DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(nonExistentIndex); | ||
|
|
||
| ElasticsearchException exception = expectThrows(ElasticsearchException.class, | ||
| () -> execute(deleteIndexRequest, highLevelClient().indices()::deleteIndex, highLevelClient().indices()::deleteIndexAsync)); | ||
| assertEquals(RestStatus.NOT_FOUND, exception.status()); | ||
| } | ||
| } | ||
|
|
||
| private static void createIndex(String index) throws IOException { | ||
| Response response = client().performRequest("PUT", index); | ||
|
|
||
| assertEquals(200, response.getStatusLine().getStatusCode()); | ||
| } | ||
|
|
||
| private static boolean indexExists(String index) throws IOException { | ||
| Response response = client().performRequest("HEAD", index); | ||
|
|
||
| return response.getStatusLine().getStatusCode() == 200; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch :) thanks for adjusting these