Skip to content

Commit

Permalink
Remove types deprecation warning for indices.exists
Browse files Browse the repository at this point in the history
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 elastic#43905
  • Loading branch information
Christoph Büscher committed Jul 4, 2019
1 parent 53f6dcf commit feaf925
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> params = new HashMap<>();
Expand All @@ -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<String, String> 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));
}
}

0 comments on commit feaf925

Please sign in to comment.