Browse Source

[Rest Api Compatibility] Typed endpoints for search and related endpoints (#72155)

Implements a V7 compatible typed endpoints for REST for search related apis
retrofits the REST layer change removed in #41640

relates main meta issue #51816
relates types removal issue #54160
Przemyslaw Gomulka 4 years ago
parent
commit
85ed9100df
27 changed files with 688 additions and 48 deletions
  1. 2 1
      client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java
  2. 14 2
      modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java
  3. 9 1
      modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java
  4. 67 0
      modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateActionTests.java
  5. 59 0
      modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/RestSearchTemplateActionTests.java
  6. 8 1
      modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestDeleteByQueryAction.java
  7. 11 1
      modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java
  8. 53 0
      modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestDeleteByQueryActionTests.java
  9. 51 0
      modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestUpdateByQueryActionTests.java
  10. 13 22
      rest-api-spec/build.gradle
  11. 5 3
      server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java
  12. 11 1
      server/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java
  13. 2 2
      server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequest.java
  14. 10 1
      server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequest.java
  15. 3 2
      server/src/main/java/org/elasticsearch/rest/DeprecationRestHandler.java
  16. 1 1
      server/src/main/java/org/elasticsearch/rest/RestRequest.java
  17. 16 1
      server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java
  18. 21 2
      server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java
  19. 18 2
      server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java
  20. 14 1
      server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java
  21. 4 0
      server/src/main/java/org/elasticsearch/search/SearchHit.java
  22. 3 1
      server/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java
  23. 4 3
      server/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java
  24. 86 0
      server/src/test/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsActionTests.java
  25. 66 0
      server/src/test/java/org/elasticsearch/rest/action/document/RestTermVectorsActionTests.java
  26. 76 0
      server/src/test/java/org/elasticsearch/rest/action/search/RestMultiSearchActionTests.java
  27. 61 0
      server/src/test/java/org/elasticsearch/rest/action/search/RestSearchActionTests.java

+ 2 - 1
client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java

@@ -47,6 +47,7 @@ import org.elasticsearch.client.core.MultiTermVectorsRequest;
 import org.elasticsearch.client.core.TermVectorsRequest;
 import org.elasticsearch.client.indices.AnalyzeRequest;
 import org.elasticsearch.common.CheckedBiConsumer;
+import org.elasticsearch.common.RestApiVersion;
 import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.bytes.BytesArray;
 import org.elasticsearch.common.bytes.BytesReference;
@@ -1227,7 +1228,7 @@ public class RequestConvertersTests extends ESTestCase {
         };
         MultiSearchRequest.readMultiLineFormat(new BytesArray(EntityUtils.toByteArray(request.getEntity())),
                 REQUEST_BODY_CONTENT_TYPE.xContent(), consumer, null, multiSearchRequest.indicesOptions(), null, null, null,
-                xContentRegistry(), true);
+                xContentRegistry(), true, RestApiVersion.current());
         assertEquals(requests, multiSearchRequest.requests());
     }
 

+ 14 - 2
modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java

@@ -9,6 +9,7 @@
 package org.elasticsearch.script.mustache;
 
 import org.elasticsearch.client.node.NodeClient;
+import org.elasticsearch.common.RestApiVersion;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.rest.BaseRestHandler;
 import org.elasticsearch.rest.RestRequest;
@@ -27,7 +28,8 @@ import static org.elasticsearch.rest.RestRequest.Method.GET;
 import static org.elasticsearch.rest.RestRequest.Method.POST;
 
 public class RestMultiSearchTemplateAction extends BaseRestHandler {
-
+    static final String TYPES_DEPRECATION_MESSAGE = "[types removal]"
+        + " Specifying types in multi search template requests is deprecated.";
     private static final Set<String> RESPONSE_PARAMS;
 
     static {
@@ -50,7 +52,13 @@ public class RestMultiSearchTemplateAction extends BaseRestHandler {
             new Route(GET, "/_msearch/template"),
             new Route(POST, "/_msearch/template"),
             new Route(GET, "/{index}/_msearch/template"),
-            new Route(POST, "/{index}/_msearch/template"));
+            new Route(POST, "/{index}/_msearch/template"),
+            Route.builder(GET, "/{index}/{type}/_msearch/template")
+                .deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7)
+                .build(),
+            Route.builder(POST, "/{index}/{type}/_msearch/template")
+                .deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7)
+                .build());
     }
 
     @Override
@@ -68,6 +76,10 @@ public class RestMultiSearchTemplateAction extends BaseRestHandler {
      * Parses a {@link RestRequest} body and returns a {@link MultiSearchTemplateRequest}
      */
     public static MultiSearchTemplateRequest parseRequest(RestRequest restRequest, boolean allowExplicitIndex) throws IOException {
+        if (restRequest.getRestApiVersion() == RestApiVersion.V_7 && restRequest.hasParam("type")) {
+            restRequest.param("type");
+        }
+
         MultiSearchTemplateRequest multiRequest = new MultiSearchTemplateRequest();
         if (restRequest.hasParam("max_concurrent_searches")) {
             multiRequest.maxConcurrentSearchRequests(restRequest.paramAsInt("max_concurrent_searches", 0));

+ 9 - 1
modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java

@@ -10,6 +10,7 @@ package org.elasticsearch.script.mustache;
 
 import org.elasticsearch.action.search.SearchRequest;
 import org.elasticsearch.client.node.NodeClient;
+import org.elasticsearch.common.RestApiVersion;
 import org.elasticsearch.common.xcontent.XContentParser;
 import org.elasticsearch.rest.BaseRestHandler;
 import org.elasticsearch.rest.RestRequest;
@@ -27,6 +28,7 @@ import static org.elasticsearch.rest.RestRequest.Method.GET;
 import static org.elasticsearch.rest.RestRequest.Method.POST;
 
 public class RestSearchTemplateAction extends BaseRestHandler {
+
     public static final String TYPED_KEYS_PARAM = "typed_keys";
     private static final Set<String> RESPONSE_PARAMS;
 
@@ -41,7 +43,13 @@ public class RestSearchTemplateAction extends BaseRestHandler {
             new Route(GET, "/_search/template"),
             new Route(POST, "/_search/template"),
             new Route(GET, "/{index}/_search/template"),
-            new Route(POST, "/{index}/_search/template"));
+            new Route(POST, "/{index}/_search/template"),
+            Route.builder(GET, "/{index}/{type}/_search/template")
+                .deprecated(RestSearchAction.TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7)
+                .build(),
+            Route.builder(POST, "/{index}/{type}/_search/template")
+                .deprecated(RestSearchAction.TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7)
+                .build());
     }
 
     @Override

+ 67 - 0
modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateActionTests.java

@@ -0,0 +1,67 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+package org.elasticsearch.script.mustache;
+
+import org.elasticsearch.common.RestApiVersion;
+import org.elasticsearch.common.bytes.BytesArray;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
+import org.elasticsearch.rest.RestRequest;
+import org.elasticsearch.test.rest.FakeRestRequest;
+import org.elasticsearch.test.rest.RestActionTestCase;
+import org.junit.Before;
+import org.mockito.Mockito;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+public class RestMultiSearchTemplateActionTests extends RestActionTestCase {
+    final List<String> contentTypeHeader = Collections.singletonList(compatibleMediaType(XContentType.VND_JSON, RestApiVersion.V_7));
+
+    @Before
+    public void setUpAction() {
+        controller().registerHandler(new RestMultiSearchTemplateAction(Settings.EMPTY));
+        //todo how to workaround this? we get AssertionError without this
+        verifyingClient.setExecuteVerifier((actionType, request) -> Mockito.mock(MultiSearchTemplateResponse.class));
+        verifyingClient.setExecuteLocallyVerifier((actionType, request) -> Mockito.mock(MultiSearchTemplateResponse.class));
+    }
+
+    public void testTypeInPath() {
+        String content = "{ \"index\": \"some_index\" } \n" +
+            "{\"source\": {\"query\" : {\"match_all\" :{}}}} \n";
+        BytesArray bytesContent = new BytesArray(content.getBytes(StandardCharsets.UTF_8));
+
+        RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
+            .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader))
+            .withMethod(RestRequest.Method.GET)
+            .withPath("/some_index/some_type/_msearch/template")
+            .withContent(bytesContent, null)
+            .build();
+
+        dispatchRequest(request);
+        assertWarnings(RestMultiSearchTemplateAction.TYPES_DEPRECATION_MESSAGE);
+    }
+
+    public void testTypeInBody() {
+        String content = "{ \"index\": \"some_index\", \"type\": \"some_type\" } \n" +
+            "{\"source\": {\"query\" : {\"match_all\" :{}}}} \n";
+        BytesArray bytesContent = new BytesArray(content.getBytes(StandardCharsets.UTF_8));
+
+        RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
+            .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader))
+            .withPath("/some_index/_msearch/template")
+            .withContent(bytesContent, null)
+            .build();
+
+        dispatchRequest(request);
+        assertWarnings(RestMultiSearchTemplateAction.TYPES_DEPRECATION_MESSAGE);
+    }
+}

+ 59 - 0
modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/RestSearchTemplateActionTests.java

@@ -0,0 +1,59 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+package org.elasticsearch.script.mustache;
+
+import org.elasticsearch.common.RestApiVersion;
+import org.elasticsearch.rest.RestRequest;
+import org.elasticsearch.rest.action.search.RestSearchAction;
+import org.elasticsearch.test.rest.FakeRestRequest;
+import org.elasticsearch.test.rest.RestActionTestCase;
+import org.junit.Before;
+import org.mockito.Mockito;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class RestSearchTemplateActionTests extends RestActionTestCase {
+    final List<String> contentTypeHeader = Collections.singletonList(randomCompatibleMediaType(RestApiVersion.V_7));
+
+    @Before
+    public void setUpAction() {
+        controller().registerHandler(new RestSearchTemplateAction());
+        verifyingClient.setExecuteVerifier((actionType, request) -> Mockito.mock(SearchTemplateResponse.class));
+        verifyingClient.setExecuteLocallyVerifier((actionType, request) -> Mockito.mock(SearchTemplateResponse.class));
+    }
+
+    public void testTypeInPath() {
+        RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
+            .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader))
+            .withMethod(RestRequest.Method.GET)
+            .withPath("/some_index/some_type/_search/template")
+            .build();
+
+        dispatchRequest(request);
+        assertWarnings(RestSearchAction.TYPES_DEPRECATION_MESSAGE);
+    }
+
+    public void testTypeParameter() {
+        Map<String, String> params = new HashMap<>();
+        params.put("type", "some_type");
+
+        RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
+            .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader))
+            .withMethod(RestRequest.Method.GET)
+            .withPath("/some_index/_search/template")
+            .withParams(params)
+            .build();
+
+        dispatchRequest(request);
+        assertWarnings(RestSearchAction.TYPES_DEPRECATION_MESSAGE);
+    }
+}

+ 8 - 1
modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestDeleteByQueryAction.java

@@ -9,8 +9,10 @@
 package org.elasticsearch.index.reindex;
 
 import org.elasticsearch.client.node.NodeClient;
+import org.elasticsearch.common.RestApiVersion;
 import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
 import org.elasticsearch.rest.RestRequest;
+import org.elasticsearch.rest.action.search.RestSearchAction;
 
 import java.io.IOException;
 import java.util.HashMap;
@@ -28,7 +30,12 @@ public class RestDeleteByQueryAction extends AbstractBulkByQueryRestHandler<Dele
 
     @Override
     public List<Route> routes() {
-        return List.of(new Route(POST, "/{index}/_delete_by_query"));
+        return List.of(new Route(POST, "/{index}/_delete_by_query"),
+            Route.builder(POST, "/{index}/{type}/_delete_by_query")
+                .deprecated(RestSearchAction.TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7)
+                .build()
+        );
+
     }
 
     @Override

+ 11 - 1
modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java

@@ -9,8 +9,10 @@
 package org.elasticsearch.index.reindex;
 
 import org.elasticsearch.client.node.NodeClient;
+import org.elasticsearch.common.RestApiVersion;
 import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
 import org.elasticsearch.rest.RestRequest;
+import org.elasticsearch.rest.action.search.RestSearchAction;
 import org.elasticsearch.script.Script;
 
 import java.io.IOException;
@@ -29,7 +31,12 @@ public class RestUpdateByQueryAction extends AbstractBulkByQueryRestHandler<Upda
 
     @Override
     public List<Route> routes() {
-        return List.of(new Route(POST, "/{index}/_update_by_query"));
+        return List.of(
+            new Route(POST, "/{index}/_update_by_query"),
+            Route.builder(POST, "/{index}/{type}/_update_by_query")
+                .deprecated(RestSearchAction.TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7)
+                .build()
+        );
     }
 
     @Override
@@ -44,6 +51,9 @@ public class RestUpdateByQueryAction extends AbstractBulkByQueryRestHandler<Upda
 
     @Override
     protected UpdateByQueryRequest buildRequest(RestRequest request, NamedWriteableRegistry namedWriteableRegistry) throws IOException {
+        if (request.getRestApiVersion() == RestApiVersion.V_7 && request.hasParam("type")) {
+            request.param("type");
+        }
         /*
          * Passing the search request through UpdateByQueryRequest first allows
          * it to set its own defaults which differ from SearchRequest's

+ 53 - 0
modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestDeleteByQueryActionTests.java

@@ -0,0 +1,53 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+package org.elasticsearch.index.reindex;
+
+import org.elasticsearch.common.RestApiVersion;
+import org.elasticsearch.common.xcontent.XContentType;
+import org.elasticsearch.rest.RestRequest;
+import org.elasticsearch.rest.action.search.RestSearchAction;
+import org.elasticsearch.test.rest.FakeRestRequest;
+import org.elasticsearch.test.rest.RestActionTestCase;
+import org.junit.Before;
+import org.mockito.Mockito;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+public class RestDeleteByQueryActionTests extends RestActionTestCase {
+
+    final List<String> contentTypeHeader = Collections.singletonList(compatibleMediaType(XContentType.VND_JSON, RestApiVersion.V_7));
+
+    @Before
+    public void setUpAction() {
+        controller().registerHandler(new RestDeleteByQueryAction());
+        verifyingClient.setExecuteVerifier((actionType, request) -> Mockito.mock(BulkByScrollResponse.class));
+        verifyingClient.setExecuteLocallyVerifier((actionType, request) -> Mockito.mock(BulkByScrollResponse.class));
+    }
+
+    public void testTypeInPath() throws IOException {
+        RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
+            .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader))
+            .withMethod(RestRequest.Method.POST)
+            .withPath("/some_index/some_type/_delete_by_query")
+            .build();
+
+        // checks the type in the URL is propagated correctly to the request object
+        // only works after the request is dispatched, so its params are filled from url.
+        dispatchRequest(request);
+
+
+        // RestDeleteByQueryAction itself doesn't check for a deprecated type usage
+        // checking here for a deprecation from its internal search request
+        assertWarnings(RestSearchAction.TYPES_DEPRECATION_MESSAGE);
+    }
+
+}

+ 51 - 0
modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestUpdateByQueryActionTests.java

@@ -0,0 +1,51 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+package org.elasticsearch.index.reindex;
+
+import org.elasticsearch.common.RestApiVersion;
+import org.elasticsearch.common.xcontent.XContentType;
+import org.elasticsearch.rest.RestRequest;
+import org.elasticsearch.rest.action.search.RestSearchAction;
+import org.elasticsearch.test.rest.FakeRestRequest;
+import org.elasticsearch.test.rest.RestActionTestCase;
+import org.junit.Before;
+import org.mockito.Mockito;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+public class RestUpdateByQueryActionTests extends RestActionTestCase {
+
+    final List<String> contentTypeHeader = Collections.singletonList(compatibleMediaType(XContentType.VND_JSON, RestApiVersion.V_7));
+
+    @Before
+    public void setUpAction() {
+        controller().registerHandler(new RestUpdateByQueryAction());
+        verifyingClient.setExecuteVerifier((actionType, request) -> Mockito.mock(BulkByScrollResponse.class));
+        verifyingClient.setExecuteLocallyVerifier((actionType, request) -> Mockito.mock(BulkByScrollResponse.class));
+    }
+
+    public void testTypeInPath() throws IOException {
+        RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
+            .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader))
+            .withMethod(RestRequest.Method.POST)
+            .withPath("/some_index/some_type/_update_by_query")
+            .build();
+
+        // checks the type in the URL is propagated correctly to the request object
+        // only works after the request is dispatched, so its params are filled from url.
+        dispatchRequest(request);
+
+        // RestUpdateByQueryAction itself doesn't check for a deprecated type usage
+        // checking here for a deprecation from its internal search request
+        assertWarnings(RestSearchAction.TYPES_DEPRECATION_MESSAGE);
+    }
+}

+ 13 - 22
rest-api-spec/build.gradle

@@ -205,33 +205,24 @@ tasks.named("yamlRestCompatTest").configure {
     'mget/71_source_filtering_with_types/Source filtering -  true/false',
     'mlt/20_docs/Basic mlt query with docs',
     'mlt/30_unlike/Basic mlt query with unlike',
-    'msearch/12_basic_with_types/Basic multi-search',
-    'msearch/12_basic_with_types/Least impact smoke test',
-    'mtermvectors/11_basic_with_types/Basic tests for multi termvector get',
     'search.aggregation/10_histogram/Deprecated _time order',
     'search.aggregation/200_top_hits_metric/top_hits aggregation with sequence numbers',
     'search.aggregation/20_terms/Deprecated _term order',
     'search.aggregation/51_filter_with_types/Filter aggs with terms lookup and ensure it\'s cached',
-    'search.inner_hits/10_basic/Nested doc version and seqIDs',
-    'search.inner_hits/10_basic/Nested inner hits',
-    'search/100_stored_fields/Stored fields',
-    'search/10_source_filtering/docvalue_fields with default format',
-    'search/110_field_collapsing/field collapsing',
-    'search/110_field_collapsing/field collapsing and from',
-    'search/110_field_collapsing/field collapsing and multiple inner_hits',
-    'search/110_field_collapsing/field collapsing, inner_hits and maxConcurrentGroupRequests',
-    'search/110_field_collapsing/field collapsing, inner_hits and seq_no',
-    'search/110_field_collapsing/field collapsing and inner_hits',
-    'search/150_rewrite_on_coordinator/Ensure that we fetch the document only once',
+    'mtermvectors/11_basic_with_types/Basic tests for multi termvector get',
+    'mtermvectors/21_deprecated_with_types/Deprecated camel case and _ parameters should fail in Term Vectors query',
+    'mtermvectors/30_mix_typeless_typeful/mtermvectors without types on an index that has types',
+    // field search on _type field- not implementing. The data for _type is considered incorrect in this search
     'search/160_exists_query/Test exists query on _type field',
-    'search/171_terms_query_with_types/Terms Query with No.of terms exceeding index.max_terms_count should FAIL',
-    'search/20_default_values/Basic search',
-    'search/260_parameter_validation/test size=-1 is deprecated',
-    'search/310_match_bool_prefix/multi_match multiple fields with cutoff_frequency throws exception',
-    'search/340_type_query/type query',
-    'search/40_indices_boost/Indices boost using object',
-    'search/70_response_filtering/Search with response filtering',
-    'search/90_search_after/search with search_after parameter',
+    //
+    'search/10_source_filtering/docvalue_fields with default format', //use_field_mapping change
+    'search/40_indices_boost/Indices boost using object', //indices_boost
+    'search/150_rewrite_on_coordinator/Ensure that we fetch the document only once', //terms_lookup
+    'search/171_terms_query_with_types/Terms Query with No.of terms exceeding index.max_terms_count should FAIL', //bulk
+    'search/260_parameter_validation/test size=-1 is deprecated', //size=-1 change
+    'search/310_match_bool_prefix/multi_match multiple fields with cutoff_frequency throws exception', //cutoff_frequency
+    'search/340_type_query/type query', // type_query - probably should behave like match_all
+
     'search_shards/10_basic/Search shards aliases with and without filters',
     'snapshot.get/10_basic/Get missing snapshot info succeeds when ignore_unavailable is true',
     'snapshot.get/10_basic/Get missing snapshot info throws an exception',

+ 5 - 3
server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java

@@ -95,9 +95,11 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte
             if (indexEntry.getValue() != null) {
                 if (builder.getRestApiVersion() == RestApiVersion.V_7 &&
                     params.paramAsBoolean(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, DEFAULT_INCLUDE_TYPE_NAME_POLICY)) {
-                    builder.startObject(MapperService.SINGLE_MAPPING_NAME);
-                    addFieldMappingsToBuilder(builder, params, indexEntry.getValue());
-                    builder.endObject();
+                    if (indexEntry.getValue().size() > 0) {
+                        builder.startObject(MapperService.SINGLE_MAPPING_NAME);
+                        addFieldMappingsToBuilder(builder, params, indexEntry.getValue());
+                        builder.endObject();
+                    }
                 } else {
                     addFieldMappingsToBuilder(builder, params, indexEntry.getValue());
                 }

+ 11 - 1
server/src/main/java/org/elasticsearch/action/search/MultiSearchRequest.java

@@ -14,15 +14,19 @@ import org.elasticsearch.action.CompositeIndicesRequest;
 import org.elasticsearch.action.support.IndicesOptions;
 import org.elasticsearch.action.support.IndicesOptions.WildcardStates;
 import org.elasticsearch.common.CheckedBiConsumer;
+import org.elasticsearch.common.RestApiVersion;
 import org.elasticsearch.common.bytes.BytesReference;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
+import org.elasticsearch.common.logging.DeprecationLogger;
 import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
 import org.elasticsearch.common.xcontent.NamedXContentRegistry;
 import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.rest.action.search.RestMultiSearchAction;
+import org.elasticsearch.rest.action.search.RestSearchAction;
 import org.elasticsearch.tasks.CancellableTask;
 import org.elasticsearch.tasks.Task;
 import org.elasticsearch.tasks.TaskId;
@@ -46,6 +50,9 @@ import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeSt
  * A multi search API request.
  */
 public class MultiSearchRequest extends ActionRequest implements CompositeIndicesRequest {
+    private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestSearchAction.class);
+    public static final String TYPES_DEPRECATION_MESSAGE = "[types removal]" +
+        " Specifying types in search requests is deprecated.";
 
     public static final int MAX_CONCURRENT_SEARCH_REQUESTS_DEFAULT = 0;
 
@@ -170,7 +177,7 @@ public class MultiSearchRequest extends ActionRequest implements CompositeIndice
                                            String searchType,
                                            Boolean ccsMinimizeRoundtrips,
                                            NamedXContentRegistry registry,
-                                           boolean allowExplicitIndex) throws IOException {
+                                           boolean allowExplicitIndex, RestApiVersion restApiVersion) throws IOException {
         int from = 0;
         byte marker = xContent.streamSeparator();
         while (true) {
@@ -231,6 +238,9 @@ public class MultiSearchRequest extends ActionRequest implements CompositeIndice
                             allowNoIndices = value;
                         } else if ("ignore_throttled".equals(entry.getKey()) || "ignoreThrottled".equals(entry.getKey())) {
                             ignoreThrottled = value;
+                        } else if(restApiVersion == RestApiVersion.V_7 &&
+                            ("type".equals(entry.getKey()) || "types".equals(entry.getKey()))) {
+                            deprecationLogger.compatibleApiWarning("msearch_with_types", RestMultiSearchAction.TYPES_DEPRECATION_MESSAGE);
                         } else {
                             throw new IllegalArgumentException("key [" + entry.getKey() + "] is not supported in the metadata section");
                         }

+ 2 - 2
server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsRequest.java

@@ -102,7 +102,7 @@ public class MultiTermVectorsRequest extends ActionRequest
                                 throw new IllegalArgumentException("docs array element should include an object");
                             }
                             TermVectorsRequest termVectorsRequest = new TermVectorsRequest(template);
-                            TermVectorsRequest.parseRequest(termVectorsRequest, parser);
+                            TermVectorsRequest.parseRequest(termVectorsRequest, parser, parser.getRestApiVersion());
                             add(termVectorsRequest);
                         }
                     } else if ("ids".equals(currentFieldName)) {
@@ -117,7 +117,7 @@ public class MultiTermVectorsRequest extends ActionRequest
                     }
                 } else if (token == XContentParser.Token.START_OBJECT && currentFieldName != null) {
                     if ("parameters".equals(currentFieldName)) {
-                        TermVectorsRequest.parseRequest(template, parser);
+                        TermVectorsRequest.parseRequest(template, parser, parser.getRestApiVersion());
                     } else {
                         throw new ElasticsearchParseException("no parameter named [{}] and type OBJECT", currentFieldName);
                     }

+ 10 - 1
server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsRequest.java

@@ -16,10 +16,12 @@ import org.elasticsearch.action.ValidateActions;
 import org.elasticsearch.action.get.MultiGetRequest;
 import org.elasticsearch.action.support.single.shard.SingleShardRequest;
 import org.elasticsearch.common.ParseField;
+import org.elasticsearch.common.RestApiVersion;
 import org.elasticsearch.common.bytes.BytesArray;
 import org.elasticsearch.common.bytes.BytesReference;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
+import org.elasticsearch.common.logging.DeprecationLogger;
 import org.elasticsearch.common.lucene.uid.Versions;
 import org.elasticsearch.common.util.set.Sets;
 import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -27,6 +29,7 @@ import org.elasticsearch.common.xcontent.XContentHelper;
 import org.elasticsearch.common.xcontent.XContentParser;
 import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.index.VersionType;
+import org.elasticsearch.rest.action.document.RestTermVectorsAction;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -46,6 +49,7 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
  * Note, the {@link #index()} and {@link #id(String)} are required.
  */
 public class TermVectorsRequest extends SingleShardRequest<TermVectorsRequest> implements RealtimeRequest {
+    private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(TermVectorsRequest.class);
 
     private static final ParseField INDEX = new ParseField("_index");
     private static final ParseField ID = new ParseField("_id");
@@ -59,6 +63,7 @@ public class TermVectorsRequest extends SingleShardRequest<TermVectorsRequest> i
     private static final ParseField DFS = new ParseField("dfs");
     private static final ParseField FILTER = new ParseField("filter");
     private static final ParseField DOC = new ParseField("doc");
+    private static final ParseField TYPE = new ParseField("_type");
 
 
     private String id;
@@ -518,7 +523,8 @@ public class TermVectorsRequest extends SingleShardRequest<TermVectorsRequest> i
     /**
      * populates a request object (pre-populated with defaults) based on a parser.
      */
-    public static void parseRequest(TermVectorsRequest termVectorsRequest, XContentParser parser) throws IOException {
+    public static void parseRequest(TermVectorsRequest termVectorsRequest, XContentParser parser, RestApiVersion restApiVersion)
+        throws IOException {
         XContentParser.Token token;
         String currentFieldName = null;
         List<String> fields = new ArrayList<>();
@@ -571,6 +577,9 @@ public class TermVectorsRequest extends SingleShardRequest<TermVectorsRequest> i
                     termVectorsRequest.version = parser.longValue();
                 } else if (VERSION_TYPE.match(currentFieldName, parser.getDeprecationHandler())) {
                     termVectorsRequest.versionType = VersionType.fromString(parser.text());
+                } else if (restApiVersion == RestApiVersion.V_7 && TYPE.match(currentFieldName, parser.getDeprecationHandler())) {
+                    deprecationLogger.compatibleApiWarning("termvectors_with_types",
+                        RestTermVectorsAction.TYPES_DEPRECATION_MESSAGE);
                 } else {
                     throw new ElasticsearchParseException("failed to parse term vectors request. unknown field [{}]", currentFieldName);
                 }

+ 3 - 2
server/src/main/java/org/elasticsearch/rest/DeprecationRestHandler.java

@@ -20,6 +20,7 @@ import java.util.Objects;
  */
 public class DeprecationRestHandler implements RestHandler {
 
+    public static final String DEPRECATED_ROUTE_KEY = "deprecated_route";
     private final RestHandler handler;
     private final String deprecationMessage;
     private final DeprecationLogger deprecationLogger;
@@ -54,9 +55,9 @@ public class DeprecationRestHandler implements RestHandler {
     @Override
     public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
         if (compatibleVersionWarning == false) {
-            deprecationLogger.deprecate(DeprecationCategory.API, "deprecated_route", deprecationMessage);
+            deprecationLogger.deprecate(DeprecationCategory.API, DEPRECATED_ROUTE_KEY, deprecationMessage);
         } else {
-            deprecationLogger.compatibleApiWarning("deprecated_route", deprecationMessage);
+            deprecationLogger.compatibleApiWarning(DEPRECATED_ROUTE_KEY, deprecationMessage);
         }
 
         handler.handleRequest(request, channel, client);

+ 1 - 1
server/src/main/java/org/elasticsearch/rest/RestRequest.java

@@ -497,7 +497,7 @@ public class RestRequest implements ToXContent.Params {
             XContentType xContentType = tuple.v1();
             try (InputStream stream = content.streamInput();
                  XContentParser parser = xContentType.xContent()
-                     .createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, stream)) {
+                     .createParserForCompatibility(xContentRegistry, LoggingDeprecationHandler.INSTANCE, stream, restApiVersion)) {
                 withParser.accept(parser);
             }
         } else {

+ 16 - 1
server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java

@@ -11,8 +11,11 @@ package org.elasticsearch.rest.action.document;
 import org.elasticsearch.action.termvectors.MultiTermVectorsRequest;
 import org.elasticsearch.action.termvectors.TermVectorsRequest;
 import org.elasticsearch.client.node.NodeClient;
+import org.elasticsearch.common.RestApiVersion;
 import org.elasticsearch.common.Strings;
+import org.elasticsearch.common.logging.DeprecationLogger;
 import org.elasticsearch.rest.BaseRestHandler;
+import org.elasticsearch.rest.DeprecationRestHandler;
 import org.elasticsearch.rest.RestRequest;
 import org.elasticsearch.rest.action.RestToXContentListener;
 
@@ -23,6 +26,8 @@ import static org.elasticsearch.rest.RestRequest.Method.GET;
 import static org.elasticsearch.rest.RestRequest.Method.POST;
 
 public class RestMultiTermVectorsAction extends BaseRestHandler {
+    DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestMultiTermVectorsAction.class);
+    static final String TYPES_DEPRECATION_MESSAGE = "[types removal] " + "Specifying types in multi term vector requests is deprecated.";
 
     @Override
     public List<Route> routes() {
@@ -30,7 +35,13 @@ public class RestMultiTermVectorsAction extends BaseRestHandler {
             new Route(GET, "/_mtermvectors"),
             new Route(POST, "/_mtermvectors"),
             new Route(GET, "/{index}/_mtermvectors"),
-            new Route(POST, "/{index}/_mtermvectors"));
+            new Route(POST, "/{index}/_mtermvectors"),
+            Route.builder(GET, "/{index}/{type}/_mtermvectors")
+                .deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7)
+                .build(),
+            Route.builder(POST, "/{index}/{type}/_mtermvectors")
+                .deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7)
+                .build());
     }
 
     @Override
@@ -40,6 +51,10 @@ public class RestMultiTermVectorsAction extends BaseRestHandler {
 
     @Override
     public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
+        if (request.getRestApiVersion() == RestApiVersion.V_7 && request.hasParam("type")) {
+            request.param("type");
+            deprecationLogger.compatibleApiWarning(DeprecationRestHandler.DEPRECATED_ROUTE_KEY, TYPES_DEPRECATION_MESSAGE);
+        }
         MultiTermVectorsRequest multiTermVectorsRequest = new MultiTermVectorsRequest();
         TermVectorsRequest template = new TermVectorsRequest()
             .index(request.param("index"));

+ 21 - 2
server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java

@@ -10,6 +10,7 @@ package org.elasticsearch.rest.action.document;
 
 import org.elasticsearch.action.termvectors.TermVectorsRequest;
 import org.elasticsearch.client.node.NodeClient;
+import org.elasticsearch.common.RestApiVersion;
 import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.xcontent.XContentParser;
 import org.elasticsearch.index.VersionType;
@@ -31,6 +32,8 @@ import static org.elasticsearch.rest.RestRequest.Method.POST;
  * TermVectorsRequest.
  */
 public class RestTermVectorsAction extends BaseRestHandler {
+    public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] " +
+        "Specifying types in term vector requests is deprecated.";
 
     @Override
     public List<Route> routes() {
@@ -38,7 +41,20 @@ public class RestTermVectorsAction extends BaseRestHandler {
             new Route(GET, "/{index}/_termvectors"),
             new Route(POST, "/{index}/_termvectors"),
             new Route(GET, "/{index}/_termvectors/{id}"),
-            new Route(POST, "/{index}/_termvectors/{id}"));
+            new Route(POST, "/{index}/_termvectors/{id}"),
+            Route.builder(GET, "/{index}/{type}/_termvectors")
+                .deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7)
+                .build(),
+            Route.builder(POST, "/{index}/{type}/_termvectors")
+                .deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7)
+                .build(),
+            Route.builder(GET, "/{index}/{type}/{id}/_termvectors")
+                .deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7)
+                .build(),
+            Route.builder(POST, "/{index}/{type}/{id}/_termvectors")
+                .deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7)
+                .build()
+        );
     }
 
     @Override
@@ -48,12 +64,15 @@ public class RestTermVectorsAction extends BaseRestHandler {
 
     @Override
     public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
+        if (request.getRestApiVersion() == RestApiVersion.V_7 && request.hasParam("type")) {
+            request.param("type");
+        }
         TermVectorsRequest termVectorsRequest;
         termVectorsRequest = new TermVectorsRequest(request.param("index"), request.param("id"));
 
         if (request.hasContentOrSourceParam()) {
             try (XContentParser parser = request.contentOrSourceParamParser()) {
-                TermVectorsRequest.parseRequest(termVectorsRequest, parser);
+                TermVectorsRequest.parseRequest(termVectorsRequest, parser, request.getRestApiVersion());
             }
         }
         readURIParameters(termVectorsRequest, request);

+ 18 - 2
server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java

@@ -14,10 +14,12 @@ import org.elasticsearch.action.search.SearchRequest;
 import org.elasticsearch.action.support.IndicesOptions;
 import org.elasticsearch.client.node.NodeClient;
 import org.elasticsearch.common.CheckedBiConsumer;
+import org.elasticsearch.common.RestApiVersion;
 import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.bytes.BytesReference;
 import org.elasticsearch.common.collect.Tuple;
 import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
+import org.elasticsearch.common.logging.DeprecationLogger;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.xcontent.XContent;
 import org.elasticsearch.common.xcontent.XContentParser;
@@ -39,6 +41,9 @@ import static org.elasticsearch.rest.RestRequest.Method.GET;
 import static org.elasticsearch.rest.RestRequest.Method.POST;
 
 public class RestMultiSearchAction extends BaseRestHandler {
+    private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestSearchAction.class);
+    public static final String TYPES_DEPRECATION_MESSAGE = "[types removal]"
+        + " Specifying types in multi search template requests is deprecated.";
 
     private static final Set<String> RESPONSE_PARAMS;
 
@@ -61,7 +66,14 @@ public class RestMultiSearchAction extends BaseRestHandler {
             new Route(GET, "/_msearch"),
             new Route(POST, "/_msearch"),
             new Route(GET, "/{index}/_msearch"),
-            new Route(POST, "/{index}/_msearch"));
+            new Route(POST, "/{index}/_msearch"),
+            Route.builder(GET, "/{index}/{type}/_msearch")
+                .deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7)
+                .build(),
+            Route.builder(POST, "/{index}/{type}/_msearch")
+                .deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7)
+                .build()
+        );
     }
 
     @Override
@@ -84,6 +96,10 @@ public class RestMultiSearchAction extends BaseRestHandler {
     public static MultiSearchRequest parseRequest(RestRequest restRequest,
                                                   NamedWriteableRegistry namedWriteableRegistry,
                                                   boolean allowExplicitIndex) throws IOException {
+        if(restRequest.getRestApiVersion() == RestApiVersion.V_7 && restRequest.hasParam("type")) {
+            restRequest.param("type");
+        }
+
         MultiSearchRequest multiRequest = new MultiSearchRequest();
         IndicesOptions indicesOptions = IndicesOptions.fromRequest(restRequest, multiRequest.indicesOptions());
         multiRequest.indicesOptions(indicesOptions);
@@ -145,7 +161,7 @@ public class RestMultiSearchAction extends BaseRestHandler {
         final XContent xContent = sourceTuple.v1().xContent();
         final BytesReference data = sourceTuple.v2();
         MultiSearchRequest.readMultiLineFormat(data, xContent, consumer, indices, indicesOptions, routing,
-                searchType, ccsMinimizeRoundtrips, request.getXContentRegistry(), allowExplicitIndex);
+                searchType, ccsMinimizeRoundtrips, request.getXContentRegistry(), allowExplicitIndex, request.getRestApiVersion());
     }
 
     @Override

+ 14 - 1
server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java

@@ -17,8 +17,10 @@ import org.elasticsearch.action.search.SearchRequest;
 import org.elasticsearch.action.support.IndicesOptions;
 import org.elasticsearch.client.node.NodeClient;
 import org.elasticsearch.common.Booleans;
+import org.elasticsearch.common.RestApiVersion;
 import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
+import org.elasticsearch.common.logging.DeprecationLogger;
 import org.elasticsearch.common.xcontent.XContentParser;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.elasticsearch.rest.BaseRestHandler;
@@ -52,6 +54,10 @@ import static org.elasticsearch.rest.RestRequest.Method.POST;
 import static org.elasticsearch.search.suggest.SuggestBuilders.termSuggestion;
 
 public class RestSearchAction extends BaseRestHandler {
+    private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestSearchAction.class);
+    public static final String TYPES_DEPRECATION_MESSAGE = "[types removal]" +
+        " Specifying types in search requests is deprecated.";
+
     /**
      * Indicates whether hits.total should be rendered as an integer or an object
      * in the rest search response.
@@ -76,11 +82,14 @@ public class RestSearchAction extends BaseRestHandler {
             new Route(GET, "/_search"),
             new Route(POST, "/_search"),
             new Route(GET, "/{index}/_search"),
-            new Route(POST, "/{index}/_search"));
+            new Route(POST, "/{index}/_search"),
+            Route.builder(GET, "/{index}/{type}/_search").deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7).build(),
+            Route.builder(POST, "/{index}/{type}/_search").deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7).build());
     }
 
     @Override
     public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
+
         SearchRequest searchRequest;
         if (request.hasParam("min_compatible_shard_node")) {
             searchRequest = new SearchRequest(Version.fromString(request.param("min_compatible_shard_node")));
@@ -120,6 +129,10 @@ public class RestSearchAction extends BaseRestHandler {
                                           XContentParser requestContentParser,
                                           NamedWriteableRegistry namedWriteableRegistry,
                                           IntConsumer setSize) throws IOException {
+        if (request.getRestApiVersion() == RestApiVersion.V_7 && request.hasParam("type")) {
+            request.param("type");
+            deprecationLogger.compatibleApiWarning("search_with_types", TYPES_DEPRECATION_MESSAGE);
+        }
 
         if (searchRequest.source() == null) {
             searchRequest.source(new SearchSourceBuilder());

+ 4 - 0
server/src/main/java/org/elasticsearch/search/SearchHit.java

@@ -15,6 +15,7 @@ import org.elasticsearch.action.OriginalIndices;
 import org.elasticsearch.common.Nullable;
 import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.ParsingException;
+import org.elasticsearch.common.RestApiVersion;
 import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.bytes.BytesReference;
 import org.elasticsearch.common.compress.CompressorFactory;
@@ -604,6 +605,9 @@ public final class SearchHit implements Writeable, ToXContentObject, Iterable<Do
         if (index != null) {
             builder.field(Fields._INDEX, RemoteClusterAware.buildRemoteIndexName(clusterAlias, index));
         }
+        if (builder.getRestApiVersion() == RestApiVersion.V_7) {
+            builder.field(MapperService.TYPE_FIELD_NAME, MapperService.SINGLE_MAPPING_NAME);
+        }
         if (id != null) {
             builder.field(Fields._ID, id);
         }

+ 3 - 1
server/src/test/java/org/elasticsearch/action/search/MultiSearchRequestTests.java

@@ -12,6 +12,7 @@ import org.elasticsearch.action.support.IndicesOptions;
 import org.elasticsearch.common.CheckedBiConsumer;
 import org.elasticsearch.common.CheckedRunnable;
 import org.elasticsearch.common.ParseField;
+import org.elasticsearch.common.RestApiVersion;
 import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.bytes.BytesArray;
 import org.elasticsearch.common.bytes.BytesReference;
@@ -245,7 +246,8 @@ public class MultiSearchRequestTests extends ESTestCase {
                 parsedRequest.add(r);
             };
             MultiSearchRequest.readMultiLineFormat(new BytesArray(originalBytes), xContentType.xContent(),
-                    consumer, null, null, null, null, null, xContentRegistry(), true);
+                    consumer, null, null, null, null, null, xContentRegistry(), true,
+                RestApiVersion.current());
             assertEquals(originalRequest, parsedRequest);
         }
     }

+ 4 - 3
server/src/test/java/org/elasticsearch/action/termvectors/TermVectorsUnitTests.java

@@ -27,6 +27,7 @@ import org.apache.lucene.search.TopDocs;
 import org.apache.lucene.store.Directory;
 import org.elasticsearch.Version;
 import org.elasticsearch.action.termvectors.TermVectorsRequest.Flag;
+import org.elasticsearch.common.RestApiVersion;
 import org.elasticsearch.common.bytes.BytesArray;
 import org.elasticsearch.common.bytes.BytesReference;
 import org.elasticsearch.common.io.stream.InputStreamStreamInput;
@@ -165,7 +166,7 @@ public class TermVectorsUnitTests extends ESTestCase {
 
         TermVectorsRequest tvr = new TermVectorsRequest(null, null);
         XContentParser parser = createParser(JsonXContent.jsonXContent, inputBytes);
-        TermVectorsRequest.parseRequest(tvr, parser);
+        TermVectorsRequest.parseRequest(tvr, parser, RestApiVersion.current());
 
         Set<String> fields = tvr.selectedFields();
         assertThat(fields.contains("a"), equalTo(true));
@@ -186,7 +187,7 @@ public class TermVectorsUnitTests extends ESTestCase {
         inputBytes = new BytesArray(" {\"offsets\":false, \"positions\":false, \"payloads\":true}");
         tvr = new TermVectorsRequest(null, null);
         parser = createParser(JsonXContent.jsonXContent, inputBytes);
-        TermVectorsRequest.parseRequest(tvr, parser);
+        TermVectorsRequest.parseRequest(tvr, parser, RestApiVersion.current());
         additionalFields = "";
         RestTermVectorsAction.addFieldStringsFromParameter(tvr, additionalFields);
         assertThat(tvr.selectedFields(), equalTo(null));
@@ -203,7 +204,7 @@ public class TermVectorsUnitTests extends ESTestCase {
         boolean threwException = false;
         try {
             XContentParser parser = createParser(JsonXContent.jsonXContent, inputBytes);
-            TermVectorsRequest.parseRequest(tvr, parser);
+            TermVectorsRequest.parseRequest(tvr, parser, RestApiVersion.current());
         } catch (Exception e) {
             threwException = true;
         }

+ 86 - 0
server/src/test/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsActionTests.java

@@ -0,0 +1,86 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+package org.elasticsearch.rest.action.document;
+
+import org.elasticsearch.action.termvectors.MultiTermVectorsResponse;
+import org.elasticsearch.common.RestApiVersion;
+import org.elasticsearch.common.bytes.BytesReference;
+import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
+import org.elasticsearch.rest.RestRequest;
+import org.elasticsearch.test.rest.FakeRestRequest;
+import org.elasticsearch.test.rest.RestActionTestCase;
+import org.junit.Before;
+import org.mockito.Mockito;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class RestMultiTermVectorsActionTests extends RestActionTestCase {
+    final List<String> contentTypeHeader = Collections.singletonList(compatibleMediaType(XContentType.VND_JSON, RestApiVersion.V_7));
+
+    @Before
+    public void setUpAction() {
+        controller().registerHandler(new RestMultiTermVectorsAction());
+        //TODO clarify why we need to set these? any workaround?
+        verifyingClient.setExecuteVerifier((actionType, request) -> Mockito.mock(MultiTermVectorsResponse.class));
+        verifyingClient.setExecuteLocallyVerifier((actionType, request) -> Mockito.mock(MultiTermVectorsResponse.class));
+    }
+
+    public void testTypeInPath() {
+        RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
+            .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader))
+            .withMethod(RestRequest.Method.POST)
+            .withPath("/some_index/some_type/_mtermvectors")
+            .build();
+
+        dispatchRequest(request);
+        assertWarnings(RestMultiTermVectorsAction.TYPES_DEPRECATION_MESSAGE);
+    }
+
+    public void testTypeParameter() {
+        Map<String, String> params = new HashMap<>();
+        params.put("type", "some_type");
+
+        RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
+            .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader))
+            .withPath("/some_index/_mtermvectors")
+            .withParams(params)
+            .build();
+
+        dispatchRequest(request);
+        assertWarnings(RestMultiTermVectorsAction.TYPES_DEPRECATION_MESSAGE);
+    }
+
+    public void testTypeInBody() throws IOException {
+        XContentBuilder content = XContentFactory.jsonBuilder()
+            .startObject()
+            .startArray("docs")
+            .startObject()
+            .field("_type", "some_type")
+            .field("_id", 1)
+            .endObject()
+            .endArray()
+            .endObject();
+
+        RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
+            .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader))
+            .withMethod(RestRequest.Method.POST)
+            .withPath("/some_index/_mtermvectors")
+            .withContent(BytesReference.bytes(content), null)
+            .build();
+
+        dispatchRequest(request);
+        assertWarnings(RestTermVectorsAction.TYPES_DEPRECATION_MESSAGE);
+    }
+}

+ 66 - 0
server/src/test/java/org/elasticsearch/rest/action/document/RestTermVectorsActionTests.java

@@ -0,0 +1,66 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+package org.elasticsearch.rest.action.document;
+
+import org.elasticsearch.action.termvectors.TermVectorsResponse;
+import org.elasticsearch.common.RestApiVersion;
+import org.elasticsearch.common.bytes.BytesReference;
+import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
+import org.elasticsearch.rest.RestRequest;
+import org.elasticsearch.test.rest.FakeRestRequest;
+import org.elasticsearch.test.rest.RestActionTestCase;
+import org.junit.Before;
+import org.mockito.Mockito;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+public class RestTermVectorsActionTests extends RestActionTestCase {
+    final List<String> contentTypeHeader = Collections.singletonList(compatibleMediaType(XContentType.VND_JSON, RestApiVersion.V_7));
+
+    @Before
+    public void setUpAction() {
+        controller().registerHandler(new RestTermVectorsAction());
+        //todo how to workaround this? we get AssertionError without this
+        verifyingClient.setExecuteVerifier((actionType, request) -> Mockito.mock(TermVectorsResponse.class));
+        verifyingClient.setExecuteLocallyVerifier((actionType, request) -> Mockito.mock(TermVectorsResponse.class));
+    }
+
+    public void testTypeInPath() {
+        RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
+            .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader))
+            .withMethod(RestRequest.Method.POST)
+            .withPath("/some_index/some_type/some_id/_termvectors")
+            .build();
+
+        dispatchRequest(request);
+        assertWarnings(RestTermVectorsAction.TYPES_DEPRECATION_MESSAGE);
+    }
+
+    public void testTypeInBody() throws IOException {
+        XContentBuilder content = XContentFactory.jsonBuilder().startObject()
+            .field("_type", "some_type")
+            .field("_id", 1)
+            .endObject();
+
+        RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
+            .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader))
+            .withMethod(RestRequest.Method.GET)
+            .withPath("/some_index/_termvectors/some_id")
+            .withContent(BytesReference.bytes(content), null)
+            .build();
+
+        dispatchRequest(request);
+        assertWarnings(RestTermVectorsAction.TYPES_DEPRECATION_MESSAGE);
+    }
+}

+ 76 - 0
server/src/test/java/org/elasticsearch/rest/action/search/RestMultiSearchActionTests.java

@@ -0,0 +1,76 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+package org.elasticsearch.rest.action.search;
+
+import org.elasticsearch.action.search.MultiSearchResponse;
+import org.elasticsearch.common.RestApiVersion;
+import org.elasticsearch.common.bytes.BytesArray;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.xcontent.XContentType;
+import org.elasticsearch.rest.RestRequest;
+import org.elasticsearch.test.rest.FakeRestRequest;
+import org.elasticsearch.test.rest.RestActionTestCase;
+import org.junit.Before;
+import org.mockito.Mockito;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class RestMultiSearchActionTests extends RestActionTestCase {
+    final List<String> contentTypeHeader = Collections.singletonList(compatibleMediaType(XContentType.VND_JSON, RestApiVersion.V_7));
+
+    private RestMultiSearchAction action;
+
+    @Before
+    public void setUpAction() {
+        action = new RestMultiSearchAction(Settings.EMPTY);
+        controller().registerHandler(action);
+        verifyingClient.setExecuteVerifier((actionType, request) -> Mockito.mock(MultiSearchResponse.class));
+        verifyingClient.setExecuteLocallyVerifier((actionType, request) -> Mockito.mock(MultiSearchResponse.class));
+    }
+
+    public void testTypeInPath() {
+        String content = "{ \"index\": \"some_index\" } \n {} \n";
+        BytesArray bytesContent = new BytesArray(content.getBytes(StandardCharsets.UTF_8));
+
+        RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
+            .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader))
+            .withMethod(RestRequest.Method.GET)
+            .withPath("/some_index/some_type/_msearch")
+            .withContent(bytesContent, null)
+            .build();
+
+        dispatchRequest(request);
+        assertWarnings(RestMultiSearchAction.TYPES_DEPRECATION_MESSAGE);
+    }
+
+    public void testTypeInBody() {
+        String content = "{ \"index\": \"some_index\", \"type\": \"some_type\" } \n {} \n";
+        BytesArray bytesContent = new BytesArray(content.getBytes(StandardCharsets.UTF_8));
+
+        RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
+            .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader))
+            .withMethod(RestRequest.Method.POST)
+            .withPath("/some_index/_msearch")
+            .withContent(bytesContent, null)
+            .build();
+
+        dispatchRequest(request);
+        assertWarnings(RestMultiSearchAction.TYPES_DEPRECATION_MESSAGE);
+    }
+
+    private Map<String, List<String>> headersWith(String accept, List<String> value) {
+        Map<String, List<String>> headers = new HashMap<>();
+        headers.put(accept, value);
+        return headers;
+    }
+}

+ 61 - 0
server/src/test/java/org/elasticsearch/rest/action/search/RestSearchActionTests.java

@@ -0,0 +1,61 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+package org.elasticsearch.rest.action.search;
+
+import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.common.RestApiVersion;
+import org.elasticsearch.rest.RestRequest;
+import org.elasticsearch.test.rest.FakeRestRequest;
+import org.elasticsearch.test.rest.RestActionTestCase;
+import org.junit.Before;
+import org.mockito.Mockito;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class RestSearchActionTests extends RestActionTestCase {
+    final List<String> contentTypeHeader = Collections.singletonList(randomCompatibleMediaType(RestApiVersion.V_7));
+
+    private RestSearchAction action;
+
+    @Before
+    public void setUpAction() {
+        action = new RestSearchAction();
+        controller().registerHandler(action);
+        verifyingClient.setExecuteVerifier((actionType, request) -> Mockito.mock(SearchResponse.class));
+        verifyingClient.setExecuteLocallyVerifier((actionType, request) -> Mockito.mock(SearchResponse.class));
+    }
+
+    public void testTypeInPath() {
+        RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
+            .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader))
+            .withMethod(RestRequest.Method.GET)
+            .withPath("/some_index/some_type/_search")
+            .build();
+
+        dispatchRequest(request);
+        assertWarnings(RestSearchAction.TYPES_DEPRECATION_MESSAGE);
+    }
+
+    public void testTypeParameter() {
+        Map<String, String> params = new HashMap<>();
+        params.put("type", "some_type");
+
+        RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
+            .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader))
+            .withMethod(RestRequest.Method.GET)
+            .withPath("/some_index/_search")
+            .withParams(params)
+            .build();
+
+        dispatchRequest(request);
+        assertWarnings(RestSearchAction.TYPES_DEPRECATION_MESSAGE);
+    }
+}