From ecb822c6664357086756d0d28fb6a4fb44b7e3b1 Mon Sep 17 00:00:00 2001 From: Julie Tibshirani Date: Wed, 19 Dec 2018 15:20:20 -0800 Subject: [PATCH] Deprecate the document create endpoint. (#36863) --- .../client/RequestConverters.java | 12 ++- .../client/RequestConvertersTests.java | 14 ++-- docs/reference/docs/index_.asciidoc | 2 +- .../resources/rest-api-spec/api/create.json | 5 +- .../rest-api-spec/test/create/10_with_id.yml | 8 +- .../test/create/11_with_id_with_types.yml | 33 ++++++++ .../test/create/15_without_id.yml | 4 +- .../test/create/15_without_id_with_types.yml | 8 ++ .../test/create/30_internal_version.yml | 11 +-- .../create/31_internal_version_with_types.yml | 35 ++++++++ .../test/create/35_external_version.yml | 6 +- .../create/36_external_version_with_types.yml | 30 +++++++ .../rest-api-spec/test/create/40_routing.yml | 7 +- .../test/create/41_routing_with_types.yml | 43 ++++++++++ .../rest-api-spec/test/create/60_refresh.yml | 14 ++-- .../test/create/61_refresh_with_types.yml | 82 +++++++++++++++++++ .../rest-api-spec/test/create/70_nested.yml | 13 +-- .../test/create/71_nested_with_types.yml | 41 ++++++++++ .../rest/action/document/RestIndexAction.java | 10 ++- .../action/document/RestIndexActionTests.java | 17 +++- 20 files changed, 349 insertions(+), 46 deletions(-) create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/create/11_with_id_with_types.yml create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/create/15_without_id_with_types.yml create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/create/31_internal_version_with_types.yml create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/create/36_external_version_with_types.yml create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/create/41_routing_with_types.yml create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/create/61_refresh_with_types.yml create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/create/71_nested_with_types.yml diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java index c7a54a9ac32..e89003f007e 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java @@ -299,8 +299,16 @@ final class RequestConverters { static Request index(IndexRequest indexRequest) { String method = Strings.hasLength(indexRequest.id()) ? HttpPut.METHOD_NAME : HttpPost.METHOD_NAME; - boolean isCreate = (indexRequest.opType() == DocWriteRequest.OpType.CREATE); - String endpoint = endpoint(indexRequest.index(), indexRequest.type(), indexRequest.id(), isCreate ? "_create" : null); + + String endpoint; + if (indexRequest.opType() == DocWriteRequest.OpType.CREATE) { + endpoint = indexRequest.type().equals(MapperService.SINGLE_MAPPING_NAME) + ? endpoint(indexRequest.index(), "_create", indexRequest.id()) + : endpoint(indexRequest.index(), indexRequest.type(), indexRequest.id(), "_create"); + } else { + endpoint = endpoint(indexRequest.index(), indexRequest.type(), indexRequest.id()); + } + Request request = new Request(method, endpoint); Params parameters = new Params(request); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java index 372b8caf1cb..698f7557c13 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java @@ -661,7 +661,7 @@ public class RequestConvertersTests extends ESTestCase { Request request = RequestConverters.index(indexRequest); if (indexRequest.opType() == DocWriteRequest.OpType.CREATE) { - assertEquals("/" + index + "/_doc/" + id + "/_create", request.getEndpoint()); + assertEquals("/" + index + "/_create/" + id, request.getEndpoint()); } else if (id != null) { assertEquals("/" + index + "/_doc/" + id, request.getEndpoint()); } else { @@ -1685,17 +1685,17 @@ public class RequestConvertersTests extends ESTestCase { assertEquals("/a/b", endpointBuilder.build()); } { - EndpointBuilder endpointBuilder = new EndpointBuilder().addPathPart("a").addPathPart("b").addPathPartAsIs("_create"); - assertEquals("/a/b/_create", endpointBuilder.build()); + EndpointBuilder endpointBuilder = new EndpointBuilder().addPathPart("a").addPathPart("b").addPathPartAsIs("_endpoint"); + assertEquals("/a/b/_endpoint", endpointBuilder.build()); } { - EndpointBuilder endpointBuilder = new EndpointBuilder().addPathPart("a", "b", "c").addPathPartAsIs("_create"); - assertEquals("/a/b/c/_create", endpointBuilder.build()); + EndpointBuilder endpointBuilder = new EndpointBuilder().addPathPart("a", "b", "c").addPathPartAsIs("_endpoint"); + assertEquals("/a/b/c/_endpoint", endpointBuilder.build()); } { - EndpointBuilder endpointBuilder = new EndpointBuilder().addPathPart("a").addPathPartAsIs("_create"); - assertEquals("/a/_create", endpointBuilder.build()); + EndpointBuilder endpointBuilder = new EndpointBuilder().addPathPart("a").addPathPartAsIs("_endpoint"); + assertEquals("/a/_endpoint", endpointBuilder.build()); } } diff --git a/docs/reference/docs/index_.asciidoc b/docs/reference/docs/index_.asciidoc index 15d78e961ab..70769b5b672 100644 --- a/docs/reference/docs/index_.asciidoc +++ b/docs/reference/docs/index_.asciidoc @@ -189,7 +189,7 @@ Another option to specify `create` is to use the following uri: [source,js] -------------------------------------------------- -PUT twitter/_doc/1/_create +PUT twitter/_create/1 { "user" : "kimchy", "post_date" : "2009-11-15T14:12:12", diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/create.json b/rest-api-spec/src/main/resources/rest-api-spec/api/create.json index 9b4e09a174a..6a21620423d 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/create.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/create.json @@ -3,8 +3,8 @@ "documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html", "methods": ["PUT","POST"], "url": { - "path": "/{index}/{type}/{id}/_create", - "paths": ["/{index}/{type}/{id}/_create"], + "path": "/{index}/_create/{id}", + "paths": ["/{index}/_create/{id}", "/{index}/{type}/{id}/_create"], "parts": { "id": { "type" : "string", @@ -18,7 +18,6 @@ }, "type": { "type" : "string", - "required" : true, "description" : "The type of the document" } }, diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/create/10_with_id.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/create/10_with_id.yml index 1e58c38c7b5..410b31acb71 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/create/10_with_id.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/create/10_with_id.yml @@ -1,25 +1,24 @@ --- "Create with ID": + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 - do: create: index: test_1 - type: test id: 1 body: { foo: bar } - match: { _index: test_1 } - - match: { _type: test } - match: { _id: "1"} - match: { _version: 1} - do: get: index: test_1 - type: test id: 1 - match: { _index: test_1 } - - match: { _type: test } - match: { _id: "1"} - match: { _version: 1} - match: { _source: { foo: bar }} @@ -28,6 +27,5 @@ catch: conflict create: index: test_1 - type: test id: 1 body: { foo: bar } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/create/11_with_id_with_types.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/create/11_with_id_with_types.yml new file mode 100644 index 00000000000..1e58c38c7b5 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/create/11_with_id_with_types.yml @@ -0,0 +1,33 @@ +--- +"Create with ID": + - do: + create: + index: test_1 + type: test + id: 1 + body: { foo: bar } + + - match: { _index: test_1 } + - match: { _type: test } + - match: { _id: "1"} + - match: { _version: 1} + + - do: + get: + index: test_1 + type: test + id: 1 + + - match: { _index: test_1 } + - match: { _type: test } + - match: { _id: "1"} + - match: { _version: 1} + - match: { _source: { foo: bar }} + + - do: + catch: conflict + create: + index: test_1 + type: test + id: 1 + body: { foo: bar } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/create/15_without_id.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/create/15_without_id.yml index ab993281938..5280c5bb994 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/create/15_without_id.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/create/15_without_id.yml @@ -1,8 +1,10 @@ --- "Create without ID": + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 - do: catch: param create: index: test_1 - type: test body: { foo: bar } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/create/15_without_id_with_types.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/create/15_without_id_with_types.yml new file mode 100644 index 00000000000..ab993281938 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/create/15_without_id_with_types.yml @@ -0,0 +1,8 @@ +--- +"Create without ID": + - do: + catch: param + create: + index: test_1 + type: test + body: { foo: bar } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/create/30_internal_version.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/create/30_internal_version.yml index 83772828bc8..52e8e464da0 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/create/30_internal_version.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/create/30_internal_version.yml @@ -1,10 +1,11 @@ --- "Internal version": - + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 - do: create: index: test_1 - type: test id: 1 body: { foo: bar } @@ -14,18 +15,18 @@ catch: conflict create: index: test_1 - type: test id: 1 body: { foo: bar } --- "Internal versioning with explicit version": - + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 - do: catch: bad_request create: index: test - type: test id: 3 body: { foo: bar } version: 5 diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/create/31_internal_version_with_types.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/create/31_internal_version_with_types.yml new file mode 100644 index 00000000000..83772828bc8 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/create/31_internal_version_with_types.yml @@ -0,0 +1,35 @@ +--- +"Internal version": + + - do: + create: + index: test_1 + type: test + id: 1 + body: { foo: bar } + + - match: { _version: 1} + + - do: + catch: conflict + create: + index: test_1 + type: test + id: 1 + body: { foo: bar } + +--- +"Internal versioning with explicit version": + + - do: + catch: bad_request + create: + index: test + type: test + id: 3 + body: { foo: bar } + version: 5 + + - match: { status: 400 } + - match: { error.type: action_request_validation_exception } + - match: { error.reason: "Validation Failed: 1: create operations do not support explicit versions. use index instead;" } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/create/35_external_version.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/create/35_external_version.yml index cb8c041d710..47dc5b60596 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/create/35_external_version.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/create/35_external_version.yml @@ -1,11 +1,12 @@ --- "External version": - + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 - do: catch: bad_request create: index: test - type: test id: 1 body: { foo: bar } version_type: external @@ -19,7 +20,6 @@ catch: bad_request create: index: test - type: test id: 2 body: { foo: bar } version_type: external diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/create/36_external_version_with_types.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/create/36_external_version_with_types.yml new file mode 100644 index 00000000000..cb8c041d710 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/create/36_external_version_with_types.yml @@ -0,0 +1,30 @@ +--- +"External version": + + - do: + catch: bad_request + create: + index: test + type: test + id: 1 + body: { foo: bar } + version_type: external + version: 0 + + - match: { status: 400 } + - match: { error.type: action_request_validation_exception } + - match: { error.reason: "Validation Failed: 1: create operations only support internal versioning. use index instead;" } + + - do: + catch: bad_request + create: + index: test + type: test + id: 2 + body: { foo: bar } + version_type: external + version: 5 + + - match: { status: 400 } + - match: { error.type: action_request_validation_exception } + - match: { error.reason: "Validation Failed: 1: create operations only support internal versioning. use index instead;" } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/create/40_routing.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/create/40_routing.yml index 752489f722c..9c048c361bd 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/create/40_routing.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/create/40_routing.yml @@ -1,6 +1,8 @@ --- "Routing": - + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 - do: indices.create: index: test_1 @@ -18,7 +20,6 @@ - do: create: index: test_1 - type: test id: 1 routing: 5 body: { foo: bar } @@ -26,7 +27,6 @@ - do: get: index: test_1 - type: test id: 1 routing: 5 stored_fields: [_routing] @@ -38,6 +38,5 @@ catch: missing get: index: test_1 - type: test id: 1 diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/create/41_routing_with_types.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/create/41_routing_with_types.yml new file mode 100644 index 00000000000..752489f722c --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/create/41_routing_with_types.yml @@ -0,0 +1,43 @@ +--- +"Routing": + + - do: + indices.create: + index: test_1 + body: + settings: + index: + number_of_shards: 5 + number_of_routing_shards: 5 + number_of_replicas: 0 + + - do: + cluster.health: + wait_for_status: green + + - do: + create: + index: test_1 + type: test + id: 1 + routing: 5 + body: { foo: bar } + + - do: + get: + index: test_1 + type: test + id: 1 + routing: 5 + stored_fields: [_routing] + + - match: { _id: "1"} + - match: { _routing: "5"} + + - do: + catch: missing + get: + index: test_1 + type: test + id: 1 + diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/create/60_refresh.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/create/60_refresh.yml index e24bdf42603..dd8acd9f99f 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/create/60_refresh.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/create/60_refresh.yml @@ -1,6 +1,8 @@ --- "Refresh": - + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 - do: indices.create: index: test_1 @@ -11,7 +13,6 @@ - do: create: index: test_1 - type: test id: 1 body: { foo: bar } @@ -27,7 +28,6 @@ - do: create: index: test_1 - type: test id: 2 refresh: true body: { foo: bar } @@ -44,10 +44,12 @@ --- "When refresh url parameter is an empty string that means \"refresh immediately\"": + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 - do: create: index: test_1 - type: test id: 1 refresh: "" body: { foo: bar } @@ -64,10 +66,12 @@ --- "refresh=wait_for waits until changes are visible in search": + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 - do: index: index: create_60_refresh_1 - type: test id: create_60_refresh_id1 body: { foo: bar } refresh: wait_for diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/create/61_refresh_with_types.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/create/61_refresh_with_types.yml new file mode 100644 index 00000000000..e24bdf42603 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/create/61_refresh_with_types.yml @@ -0,0 +1,82 @@ +--- +"Refresh": + + - do: + indices.create: + index: test_1 + body: + settings: + index.refresh_interval: -1 + number_of_replicas: 0 + - do: + create: + index: test_1 + type: test + id: 1 + body: { foo: bar } + + - do: + search: + rest_total_hits_as_int: true + index: test_1 + body: + query: { term: { _id: 1 }} + + - match: { hits.total: 0 } + + - do: + create: + index: test_1 + type: test + id: 2 + refresh: true + body: { foo: bar } + - is_true: forced_refresh + + - do: + search: + rest_total_hits_as_int: true + index: test_1 + body: + query: { term: { _id: 2 }} + + - match: { hits.total: 1 } + +--- +"When refresh url parameter is an empty string that means \"refresh immediately\"": + - do: + create: + index: test_1 + type: test + id: 1 + refresh: "" + body: { foo: bar } + - is_true: forced_refresh + + - do: + search: + rest_total_hits_as_int: true + index: test_1 + body: + query: { term: { _id: 1 }} + + - match: { hits.total: 1 } + +--- +"refresh=wait_for waits until changes are visible in search": + - do: + index: + index: create_60_refresh_1 + type: test + id: create_60_refresh_id1 + body: { foo: bar } + refresh: wait_for + - is_false: forced_refresh + + - do: + search: + rest_total_hits_as_int: true + index: create_60_refresh_1 + body: + query: { term: { _id: create_60_refresh_id1 }} + - match: { hits.total: 1 } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/create/70_nested.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/create/70_nested.yml index 2c912a2165a..1d6bd5bd703 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/create/70_nested.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/create/70_nested.yml @@ -1,16 +1,19 @@ --- setup: + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 - do: indices.create: + include_type_name: false index: test_1 body: settings: index.mapping.nested_objects.limit: 2 mappings: - test_type: - properties: - nested1: - type: nested + properties: + nested1: + type: nested --- "Indexing a doc with No. nested objects less or equal to index.mapping.nested_objects.limit should succeed": @@ -20,7 +23,6 @@ setup: - do: create: index: test_1 - type: test_type id: 1 body: "nested1" : [ { "foo": "bar" }, { "foo": "bar2" } ] @@ -35,7 +37,6 @@ setup: catch: /The number of nested documents has exceeded the allowed limit of \[2\]. This limit can be set by changing the \[index.mapping.nested_objects.limit\] index level setting\./ create: index: test_1 - type: test_type id: 1 body: "nested1" : [ { "foo": "bar" }, { "foo": "bar2" }, { "foo": "bar3" } ] diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/create/71_nested_with_types.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/create/71_nested_with_types.yml new file mode 100644 index 00000000000..2c912a2165a --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/create/71_nested_with_types.yml @@ -0,0 +1,41 @@ +--- +setup: + - do: + indices.create: + index: test_1 + body: + settings: + index.mapping.nested_objects.limit: 2 + mappings: + test_type: + properties: + nested1: + type: nested + +--- +"Indexing a doc with No. nested objects less or equal to index.mapping.nested_objects.limit should succeed": + - skip: + version: " - 6.99.99" + reason: index.mapping.nested_objects setting has been added in 7.0.0 + - do: + create: + index: test_1 + type: test_type + id: 1 + body: + "nested1" : [ { "foo": "bar" }, { "foo": "bar2" } ] + - match: { _version: 1} + +--- +"Indexing a doc with No. nested objects more than index.mapping.nested_objects.limit should fail": + - skip: + version: " - 6.99.99" + reason: index.mapping.nested_objects setting has been added in 7.0.0 + - do: + catch: /The number of nested documents has exceeded the allowed limit of \[2\]. This limit can be set by changing the \[index.mapping.nested_objects.limit\] index level setting\./ + create: + index: test_1 + type: test_type + id: 1 + body: + "nested1" : [ { "foo": "bar" }, { "foo": "bar2" }, { "foo": "bar3" } ] 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 bd18dae7454..7c10b327cac 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 @@ -42,15 +42,19 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestIndexAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestDeleteAction.class)); - public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in " + - "document index requests is deprecated, use the /{index}/_doc/{id} or /{index}/_doc endpoints instead."; + public 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})."; public RestIndexAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(POST, "/{index}/{type}", this); // auto id creation controller.registerHandler(PUT, "/{index}/{type}/{id}", this); controller.registerHandler(POST, "/{index}/{type}/{id}", this); + CreateHandler createHandler = new CreateHandler(settings); + controller.registerHandler(PUT, "/{index}/_create/{id}", createHandler); + controller.registerHandler(POST, "/{index}/_create/{id}/", createHandler); controller.registerHandler(PUT, "/{index}/{type}/{id}/_create", createHandler); controller.registerHandler(POST, "/{index}/{type}/{id}/_create", createHandler); } @@ -88,7 +92,7 @@ public class RestIndexAction extends BaseRestHandler { public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { IndexRequest indexRequest; final String type = request.param("type"); - if (type.equals(MapperService.SINGLE_MAPPING_NAME) == false) { + if (type != null && type.equals(MapperService.SINGLE_MAPPING_NAME) == false) { deprecationLogger.deprecatedAndMaybeLog("index_with_types", TYPES_DEPRECATION_MESSAGE); indexRequest = new IndexRequest(request.param("index"), type, request.param("id")); } else { 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 5fe99589a64..1f45f5265ac 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 @@ -52,7 +52,22 @@ public class RestIndexActionTests extends RestActionTestCase { dispatchRequest(validRequest); } - public void testCreateOpTypeValidation() throws Exception { + public void testCreateWithTypeInPath() { + RestRequest deprecatedRequest = new FakeRestRequest.Builder(xContentRegistry()) + .withMethod(RestRequest.Method.PUT) + .withPath("/some_index/some_type/some_id/_create") + .build(); + dispatchRequest(deprecatedRequest); + assertWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE); + + RestRequest validRequest = new FakeRestRequest.Builder(xContentRegistry()) + .withMethod(RestRequest.Method.PUT) + .withPath("/some_index/_create/some_id") + .build(); + dispatchRequest(validRequest); + } + + public void testCreateOpTypeValidation() { Settings settings = settings(Version.CURRENT).build(); RestIndexAction.CreateHandler create = action.new CreateHandler(settings);