Skip to content

Deprecate the document create endpoint. #36863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,16 @@ static Request multiGet(MultiGetRequest multiGetRequest) throws IOException {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ public void testIndex() throws IOException {

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 {
Expand Down Expand Up @@ -1685,17 +1685,17 @@ public void testEndpointBuilder() {
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());
}
}

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/docs/index_.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -18,7 +18,6 @@
},
"type": {
"type" : "string",
"required" : true,
"description" : "The type of the document"
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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 }}
Expand All @@ -28,6 +27,5 @@
catch: conflict
create:
index: test_1
type: test
id: 1
body: { foo: bar }
Original file line number Diff line number Diff line change
@@ -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 }
Original file line number Diff line number Diff line change
@@ -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 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"Create without ID":
- do:
catch: param
create:
index: test_1
type: test
body: { foo: bar }
Original file line number Diff line number Diff line change
@@ -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 }

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;" }
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,7 +20,6 @@
catch: bad_request
create:
index: test
type: test
id: 2
body: { foo: bar }
version_type: external
Expand Down
Original file line number Diff line number Diff line change
@@ -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;" }
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,15 +20,13 @@
- 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]
Expand All @@ -38,6 +38,5 @@
catch: missing
get:
index: test_1
type: test
id: 1

Original file line number Diff line number Diff line change
@@ -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

Loading