diff --git a/rest-api-spec/build.gradle b/rest-api-spec/build.gradle index e52d80a89d230..e8101d069f359 100644 --- a/rest-api-spec/build.gradle +++ b/rest-api-spec/build.gradle @@ -143,22 +143,9 @@ tasks.named("yamlRestCompatTest").configure { 'explain/40_mix_typeless_typeful/Explain with typeless API on an index that has types', 'field_caps/10_basic/Get date_nanos field caps', 'field_caps/30_filter/Field caps with index filter', - 'get/100_mix_typeless_typeful/GET with typeless API on an index that has types', - 'get/10_basic/Basic', - 'get/11_basic_with_types/Basic', - 'get/15_default_values/Default values', - 'get/16_default_values_with_types/Default values', - 'get/20_stored_fields/Stored fields', - 'get/21_stored_fields_with_types/Stored fields', - 'get/41_routing_with_types/Routing', - 'get/50_with_headers/REST test with headers', - 'get/51_with_headers_with_types/REST test with headers', - 'get/61_realtime_refresh_with_types/Realtime Refresh', - 'get/70_source_filtering/Source filtering', - 'get/71_source_filtering_with_types/Source filtering', - 'get/81_missing_with_types/Missing document with catch', - 'get/81_missing_with_types/Missing document with ignore', - 'get/91_versions_with_types/Versions', + 'get/100_mix_typeless_typeful/GET with typeless API on an index that has types',// failing due to include_type_name #48632 + 'get/21_stored_fields_with_types/Stored fields', // failing due to include_type_name #48632 + 'get/71_source_filtering_with_types/Source filtering',// failing due to include_type_name #48632 'get_source/11_basic_with_types/Basic with types', 'get_source/16_default_values_with_types/Default values', 'get_source/41_routing_with_types/Routing', @@ -168,20 +155,8 @@ tasks.named("yamlRestCompatTest").configure { 'get_source/81_missing_with_types/Missing document with ignore', 'get_source/86_source_missing_with_types/Missing document source with catch', 'get_source/86_source_missing_with_types/Missing document source with ignore', - 'index/10_with_id/Index with ID', - 'index/11_with_id_with_types/Index with ID', - 'index/13_result_with_types/Index result field', - 'index/15_without_id/Index without ID', - 'index/16_without_id_with_types/Index without ID', - 'index/21_optype_with_types/Optype', - 'index/37_external_version_with_types/External version', - 'index/38_external_gte_version_with_types/External GTE version', - 'index/41_routing_with_types/Routing', - 'index/61_refresh_with_types/Refresh', - 'index/61_refresh_with_types/When refresh url parameter is an empty string that means "refresh immediately"', - 'index/61_refresh_with_types/refresh=wait_for waits until changes are visible in search', - 'index/70_mix_typeless_typeful/Index call that introduces new field mappings', - 'index/70_mix_typeless_typeful/Index with typeless API on an index that has types', + 'index/70_mix_typeless_typeful/Index call that introduces new field mappings', // failing due to include_type_name #48632 + 'index/70_mix_typeless_typeful/Index with typeless API on an index that has types', // failing due to include_type_name #48632 'indices.clone/10_basic/Clone index via API', 'indices.create/10_basic/Create index with explicit _doc type', 'indices.create/10_basic/Create index without soft deletes', @@ -376,3 +351,8 @@ tasks.named("yamlRestCompatTest").configure { 'update/90_mix_typeless_typeful/Update with typeless API on an index that has types' ].join(',') } + +tasks.named("transformV7RestTests").configure({ task -> + task.replaceMatch("_type", "_doc") + task.addAllowedWarningRegex("\\[types removal\\].*") +}) diff --git a/server/src/main/java/org/elasticsearch/action/DocWriteResponse.java b/server/src/main/java/org/elasticsearch/action/DocWriteResponse.java index 70b6ee4d49406..11719ec413fdd 100644 --- a/server/src/main/java/org/elasticsearch/action/DocWriteResponse.java +++ b/server/src/main/java/org/elasticsearch/action/DocWriteResponse.java @@ -14,6 +14,7 @@ import org.elasticsearch.action.support.replication.ReplicationResponse; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.RestApiVersion; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -293,6 +294,9 @@ private void writeWithoutShardId(StreamOutput out) throws IOException { @Override public final XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); + if (builder.getRestApiVersion() == RestApiVersion.V_7) { + builder.field(MapperService.TYPE_FIELD_NAME, MapperService.SINGLE_MAPPING_NAME); + } innerToXContent(builder, params); builder.endObject(); return builder; diff --git a/server/src/main/java/org/elasticsearch/index/get/GetResult.java b/server/src/main/java/org/elasticsearch/index/get/GetResult.java index 12d87a950d913..9d3da1c5239f9 100644 --- a/server/src/main/java/org/elasticsearch/index/get/GetResult.java +++ b/server/src/main/java/org/elasticsearch/index/get/GetResult.java @@ -10,6 +10,7 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.Version; +import org.elasticsearch.common.RestApiVersion; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.compress.CompressorFactory; @@ -282,6 +283,9 @@ public XContentBuilder toXContentEmbedded(XContentBuilder builder, Params params public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.field(_INDEX, index); + if (builder.getRestApiVersion() == RestApiVersion.V_7) { + builder.field(MapperService.TYPE_FIELD_NAME, MapperService.SINGLE_MAPPING_NAME); + } builder.field(_ID, id); if (isExists()) { if (version != -1) { diff --git a/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java index af87c3fd60e89..36cc35160dc43 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -77,6 +77,7 @@ public enum MergeReason { } public static final String SINGLE_MAPPING_NAME = "_doc"; + public static final String TYPE_FIELD_NAME = "_type"; public static final Setting INDEX_MAPPING_NESTED_FIELDS_LIMIT_SETTING = Setting.longSetting("index.mapping.nested_fields.limit", 50L, 0, Property.Dynamic, Property.IndexScope); // maximum allowed number of nested json objects across all fields in a single document diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java index 9532cfbcdc997..a6a47f0baebb6 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java @@ -11,6 +11,7 @@ import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.common.RestApiVersion; import org.elasticsearch.common.Strings; import org.elasticsearch.index.VersionType; import org.elasticsearch.rest.BaseRestHandler; @@ -29,6 +30,8 @@ import static org.elasticsearch.rest.RestStatus.OK; public class RestGetAction extends BaseRestHandler { + static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in " + + "document get requests is deprecated, use the /{index}/_doc/{id} endpoint instead."; @Override public String getName() { @@ -39,11 +42,21 @@ public String getName() { public List routes() { return List.of( new Route(GET, "/{index}/_doc/{id}"), - new Route(HEAD, "/{index}/_doc/{id}")); + new Route(HEAD, "/{index}/_doc/{id}"), + Route.builder(GET, "/{index}/{type}/{id}") + .deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7) + .build(), + Route.builder(HEAD, "/{index}/{type}/{id}") + .deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7) + .build()); } @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { + if (request.getRestApiVersion() == RestApiVersion.V_7) { + request.param("type"); // consume and ignore the type + } + GetRequest getRequest = new GetRequest(request.param("index"), request.param("id")); getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh())); diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java index 2c6aa2f3e3c55..7756a6f3c241c 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java @@ -14,6 +14,7 @@ import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.RestApiVersion; import org.elasticsearch.index.VersionType; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; @@ -29,12 +30,21 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestIndexAction extends BaseRestHandler { + static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in document " + + "index requests is deprecated, use the typeless endpoints instead (/{index}/_doc/{id}, /{index}/_doc, " + + "or /{index}/_create/{id})."; @Override public List routes() { return List.of( new Route(POST, "/{index}/_doc/{id}"), - new Route(PUT, "/{index}/_doc/{id}")); + new Route(PUT, "/{index}/_doc/{id}"), + Route.builder(POST, "/{index}/{type}/{id}") + .deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7) + .build(), + Route.builder(PUT, "/{index}/{type}/{id}") + .deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7) + .build()); } @Override @@ -53,7 +63,13 @@ public String getName() { public List routes() { return List.of( new Route(POST, "/{index}/_create/{id}"), - new Route(PUT, "/{index}/_create/{id}")); + new Route(PUT, "/{index}/_create/{id}"), + Route.builder(POST, "/{index}/{type}/{id}/_create") + .deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7) + .build(), + Route.builder(PUT, "/{index}/{type}/{id}/_create") + .deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7) + .build()); } @Override @@ -85,7 +101,11 @@ public String getName() { @Override public List routes() { - return List.of(new Route(POST, "/{index}/_doc")); + return List.of( + new Route(POST, "/{index}/_doc"), + Route.builder(POST, "/{index}/{type}") + .deprecated(TYPES_DEPRECATION_MESSAGE, RestApiVersion.V_7) + .build()); } @Override @@ -101,6 +121,10 @@ public RestChannelConsumer prepareRequest(RestRequest request, final NodeClient @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { + if (request.getRestApiVersion() == RestApiVersion.V_7) { + request.param("type"); // consume and ignore the type + } + IndexRequest indexRequest = new IndexRequest(request.param("index")); indexRequest.id(request.param("id")); indexRequest.routing(request.param("routing")); diff --git a/server/src/test/java/org/elasticsearch/action/DocWriteResponseTests.java b/server/src/test/java/org/elasticsearch/action/DocWriteResponseTests.java index 0cfe1b9422fdd..f20e8ccaaa23e 100644 --- a/server/src/test/java/org/elasticsearch/action/DocWriteResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/DocWriteResponseTests.java @@ -10,11 +10,13 @@ import org.elasticsearch.action.DocWriteResponse.Result; import org.elasticsearch.action.support.replication.ReplicationResponse.ShardInfo; +import org.elasticsearch.common.RestApiVersion; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; +import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.seqno.SequenceNumbers; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.test.ESTestCase; @@ -96,4 +98,35 @@ public void testToXContentDoesntIncludeForcedRefreshUnlessForced() throws IOExce } } } + + public void testTypeWhenCompatible() throws IOException { + DocWriteResponse response = new DocWriteResponse( + new ShardId("index", "uuid", 0), + "id", + SequenceNumbers.UNASSIGNED_SEQ_NO, + 17, + 0, + DocWriteResponse.Result.CREATED + ) { + // DocWriteResponse is abstract so we have to sneak a subclass in here to test it. + }; + try (XContentBuilder builder = JsonXContent.contentBuilder()) { + builder.withCompatibleVersion(RestApiVersion.V_7); + response.toXContent(builder, ToXContent.EMPTY_PARAMS); + + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + assertThat(parser.map(), hasEntry(MapperService.TYPE_FIELD_NAME, MapperService.SINGLE_MAPPING_NAME)); + } + } + + try (XContentBuilder builder = JsonXContent.contentBuilder()) { + builder.withCompatibleVersion(RestApiVersion.V_8); + response.toXContent(builder, ToXContent.EMPTY_PARAMS); + + try (XContentParser parser = createParser(JsonXContent.jsonXContent, BytesReference.bytes(builder))) { + assertThat(parser.map(), not(hasKey(MapperService.TYPE_FIELD_NAME))); + } + } + } + } diff --git a/server/src/test/java/org/elasticsearch/index/get/GetResultTests.java b/server/src/test/java/org/elasticsearch/index/get/GetResultTests.java index a47a6e9559a76..80ff2585fac0b 100644 --- a/server/src/test/java/org/elasticsearch/index/get/GetResultTests.java +++ b/server/src/test/java/org/elasticsearch/index/get/GetResultTests.java @@ -8,6 +8,7 @@ package org.elasticsearch.index.get; +import org.elasticsearch.common.RestApiVersion; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -15,9 +16,11 @@ import org.elasticsearch.common.document.DocumentField; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.index.mapper.IdFieldMapper; import org.elasticsearch.index.mapper.IndexFieldMapper; import org.elasticsearch.index.mapper.SeqNoFieldMapper; @@ -86,6 +89,34 @@ public void testToXContent() throws IOException { } } + public void testToCompatibleXContent() throws IOException { + { + GetResult getResult = new GetResult("index", "id", 0, 1, 1, true, new BytesArray("{ \"field1\" : " + + "\"value1\", \"field2\":\"value2\"}"), singletonMap("field1", new DocumentField("field1", + singletonList("value1"))), singletonMap("field1", new DocumentField("metafield", + singletonList("metavalue")))); + + try (XContentBuilder builder = JsonXContent.contentBuilder()) { + builder.withCompatibleVersion(RestApiVersion.V_7); + getResult.toXContent(builder, ToXContent.EMPTY_PARAMS); + String output = Strings.toString(builder); + assertEquals("{\"_index\":\"index\",\"_type\":\"_doc\",\"_id\":\"id\",\"_version\":1,\"_seq_no\":0,\"_primary_term\":1," + + "\"metafield\":\"metavalue\",\"found\":true,\"_source\":{ \"field1\" : \"value1\", \"field2\":\"value2\"}," + + "\"fields\":{\"field1\":[\"value1\"]}}", output); + } + } + { + GetResult getResult = new GetResult("index", "id", UNASSIGNED_SEQ_NO, 0, 1, false, null, null, null); + + try (XContentBuilder builder = JsonXContent.contentBuilder()) { + builder.withCompatibleVersion(RestApiVersion.V_7); + getResult.toXContent(builder, ToXContent.EMPTY_PARAMS); + String output = Strings.toString(builder); + assertEquals("{\"_index\":\"index\",\"_type\":\"_doc\",\"_id\":\"id\",\"found\":false}", output); + } + } + } + public void testToAndFromXContentEmbedded() throws Exception { XContentType xContentType = randomFrom(XContentType.values()); Tuple tuple = randomGetResult(xContentType); diff --git a/server/src/test/java/org/elasticsearch/rest/RestControllerTests.java b/server/src/test/java/org/elasticsearch/rest/RestControllerTests.java index bd684b3d3cd50..bf535e3a205ea 100644 --- a/server/src/test/java/org/elasticsearch/rest/RestControllerTests.java +++ b/server/src/test/java/org/elasticsearch/rest/RestControllerTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.rest; -import org.elasticsearch.Version; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.RestApiVersion; import org.elasticsearch.common.breaker.CircuitBreaker; @@ -630,7 +629,7 @@ public void testDispatchCompatibleHandler() { RestController restController = new RestController(Collections.emptySet(), null, client, circuitBreakerService, usageService); - final byte version = RestApiVersion.minimumSupported().major; + final RestApiVersion version = RestApiVersion.minimumSupported(); final String mediaType = randomCompatibleMediaType(version); FakeRestRequest fakeRestRequest = requestWithContent(mediaType); @@ -654,7 +653,7 @@ public void testDispatchCompatibleRequestToNewlyAddedHandler() { RestController restController = new RestController(Collections.emptySet(), null, client, circuitBreakerService, usageService); - final byte version = RestApiVersion.minimumSupported().major; + final RestApiVersion version = RestApiVersion.minimumSupported(); final String mediaType = randomCompatibleMediaType(version); FakeRestRequest fakeRestRequest = requestWithContent(mediaType); @@ -690,7 +689,7 @@ private FakeRestRequest requestWithContent(String mediaType) { public void testCurrentVersionVNDMediaTypeIsNotUsingCompatibility() { RestController restController = new RestController(Collections.emptySet(), null, client, circuitBreakerService, usageService); - final byte version = Version.CURRENT.major; + final RestApiVersion version = RestApiVersion.current(); final String mediaType = randomCompatibleMediaType(version); FakeRestRequest fakeRestRequest = requestWithContent(mediaType); diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestGetActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestGetActionTests.java new file mode 100644 index 0000000000000..2e403e4a7d015 --- /dev/null +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestGetActionTests.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.rest.action.document; + +import org.elasticsearch.action.get.GetRequest; +import org.elasticsearch.action.get.GetResponse; +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.List; +import java.util.Map; + +import static org.hamcrest.Matchers.instanceOf; + +public class RestGetActionTests extends RestActionTestCase { + final List contentTypeHeader = Collections.singletonList(randomCompatibleMediaType(RestApiVersion.V_7)); + + @Before + public void setUpAction() { + controller().registerHandler(new RestGetAction()); + verifyingClient.setExecuteVerifier((actionType, request) -> { + assertThat(request, instanceOf(GetRequest.class)); + return Mockito.mock(GetResponse.class); + }); + } + + public void testTypeInPathWithGet() { + FakeRestRequest.Builder deprecatedRequest = new FakeRestRequest.Builder(xContentRegistry()).withHeaders( + Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader) + ).withPath("/some_index/some_type/some_id"); + dispatchRequest(deprecatedRequest.withMethod(RestRequest.Method.GET).build()); + assertWarnings(RestGetAction.TYPES_DEPRECATION_MESSAGE); + } + + public void testTypeInPathWithHead() { + FakeRestRequest.Builder deprecatedRequest = new FakeRestRequest.Builder(xContentRegistry()).withHeaders( + Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader) + ).withPath("/some_index/some_type/some_id"); + dispatchRequest(deprecatedRequest.withMethod(RestRequest.Method.HEAD).build()); + assertWarnings(RestGetAction.TYPES_DEPRECATION_MESSAGE); + } +} diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestIndexActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestIndexActionTests.java index b864ac16b17f2..41379f80e0c55 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestIndexActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestIndexActionTests.java @@ -17,6 +17,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.RestApiVersion; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.shard.ShardId; @@ -28,6 +29,9 @@ import org.elasticsearch.test.rest.RestActionTestCase; import org.junit.Before; +import java.util.Collections; +import java.util.List; +import java.util.Map; import java.util.concurrent.atomic.AtomicReference; import static org.hamcrest.Matchers.equalTo; @@ -35,6 +39,8 @@ public class RestIndexActionTests extends RestActionTestCase { + final List contentTypeHeader = Collections.singletonList(randomCompatibleMediaType(RestApiVersion.V_7)); + private final AtomicReference clusterStateSupplier = new AtomicReference<>(); @Before @@ -84,4 +90,34 @@ private void checkAutoIdOpType(Version minClusterVersion, DocWriteRequest.OpType dispatchRequest(autoIdRequest); assertThat(executeCalled.get(), equalTo(true)); } + + public void testTypeInPath() { + // using CompatibleRestIndexAction + RestRequest deprecatedRequest = new FakeRestRequest.Builder(xContentRegistry()).withMethod(RestRequest.Method.PUT) + .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader)) + .withPath("/some_index/some_type/some_id") + .build(); + dispatchRequest(deprecatedRequest); + assertWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE); + } + + public void testCreateWithTypeInPath() { + // using CompatibleCreateHandler + RestRequest deprecatedRequest = new FakeRestRequest.Builder(xContentRegistry()).withMethod(RestRequest.Method.PUT) + .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader)) + .withPath("/some_index/some_type/some_id/_create") + .build(); + dispatchRequest(deprecatedRequest); + assertWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE); + } + + public void testAutoIdWithType() { + // using CompatibleAutoIdHandler + RestRequest deprecatedRequest = new FakeRestRequest.Builder(xContentRegistry()).withMethod(RestRequest.Method.POST) + .withHeaders(Map.of("Content-Type", contentTypeHeader, "Accept", contentTypeHeader)) + .withPath("/some_index/some_type/") + .build(); + dispatchRequest(deprecatedRequest); + assertWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE); + } } diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index a18fd0d6bcd5d..e60dfbafdb62c 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -1138,10 +1138,10 @@ public static Class getTestTransportPlugin() { private static final GeohashGenerator geohashGenerator = new GeohashGenerator(); - public String randomCompatibleMediaType(byte version) { + public String randomCompatibleMediaType(RestApiVersion version) { XContentType type = randomFrom(XContentType.VND_JSON, XContentType.VND_SMILE, XContentType.VND_CBOR, XContentType.VND_YAML); return type.toParsedMediaType() - .responseContentTypeHeader(Map.of(MediaType.COMPATIBLE_WITH_PARAMETER_NAME, String.valueOf(version))); + .responseContentTypeHeader(Map.of(MediaType.COMPATIBLE_WITH_PARAMETER_NAME, String.valueOf(version.major))); } public static class GeohashGenerator extends CodepointSetGenerator {