From aeb3c1fd1b0d25da5696441155aa25961a3bf5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Thu, 4 Jul 2019 16:40:31 +0200 Subject: [PATCH] Prevent types deprecation warning for indices.exists requests (#43963) Currently we log a deprecation warning to the types removal in RestGetIndicesAction even if the REST method is HEAD, which is used by the indices.exists API. Since the body is empty in this case we should not need to show the deprecation warning. Closes #43905 --- .../elasticsearch/client/IndicesClientIT.java | 3 +-- .../admin/indices/RestGetIndicesAction.java | 4 ++-- .../indices/RestGetIndicesActionTests.java | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) 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 59d76142566e6..a050693e04c02 100644 --- 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 @@ -192,8 +192,7 @@ public void testIndicesExistsWithTypes() throws IOException { = new org.elasticsearch.action.admin.indices.get.GetIndexRequest(); request.indices(indexName); - boolean response = execute(request, highLevelClient().indices()::exists, highLevelClient().indices()::existsAsync, - expectWarnings(RestGetIndicesAction.TYPES_DEPRECATION_MESSAGE)); + boolean response = execute(request, highLevelClient().indices()::exists, highLevelClient().indices()::existsAsync); assertTrue(response); } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java index 842741872fdb2..6649863e8520e 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java @@ -70,8 +70,8 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { String[] indices = Strings.splitStringByCommaToArray(request.param("index")); - // starting with 7.0 we don't include types by default in the response - if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER)) { + // starting with 7.0 we don't include types by default in the response to GET requests + if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER) && request.method().equals(GET)) { deprecationLogger.deprecatedAndMaybeLog("get_indices_with_types", TYPES_DEPRECATION_MESSAGE); } final GetIndexRequest getIndexRequest = new GetIndexRequest(); diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesActionTests.java index e4eb0edbb8582..3490e8f2c8844 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesActionTests.java @@ -36,7 +36,7 @@ public class RestGetIndicesActionTests extends RestActionTestCase { /** - * Test that setting the "include_type_name" parameter raises a warning + * Test that setting the "include_type_name" parameter raises a warning for the GET request */ public void testIncludeTypeNamesWarning() throws IOException { Map params = new HashMap<>(); @@ -58,4 +58,20 @@ public void testIncludeTypeNamesWarning() throws IOException { .build(); handler.prepareRequest(request, mock(NodeClient.class)); } + + /** + * Test that setting the "include_type_name" parameter doesn't raises a warning if the HEAD method is used (indices.exists) + */ + public void testIncludeTypeNamesWarningExists() throws IOException { + Map params = new HashMap<>(); + params.put(INCLUDE_TYPE_NAME_PARAMETER, randomFrom("true", "false")); + RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) + .withMethod(RestRequest.Method.HEAD) + .withPath("/some_index") + .withParams(params) + .build(); + + RestGetIndicesAction handler = new RestGetIndicesAction(Settings.EMPTY, mock(RestController.class)); + handler.prepareRequest(request, mock(NodeClient.class)); + } }