Skip to content

Commit e4e1688

Browse files
committed
Deprecate types in document delete requests.
1 parent 92935a7 commit e4e1688

File tree

11 files changed

+134
-35
lines changed

11 files changed

+134
-35
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void testDelete() throws IOException {
9898
String docId = "id";
9999
highLevelClient().index(
100100
new IndexRequest("index", "_doc", docId).source(Collections.singletonMap("foo", "bar")), RequestOptions.DEFAULT);
101-
DeleteRequest deleteRequest = new DeleteRequest("index", "_doc", docId);
101+
DeleteRequest deleteRequest = new DeleteRequest("index", docId);
102102
if (randomBoolean()) {
103103
deleteRequest.version(1L);
104104
}
@@ -111,7 +111,7 @@ public void testDelete() throws IOException {
111111
{
112112
// Testing non existing document
113113
String docId = "does_not_exist";
114-
DeleteRequest deleteRequest = new DeleteRequest("index", "_doc", docId);
114+
DeleteRequest deleteRequest = new DeleteRequest("index", docId);
115115
DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync);
116116
assertEquals("index", deleteResponse.getIndex());
117117
assertEquals("_doc", deleteResponse.getType());
@@ -123,7 +123,7 @@ public void testDelete() throws IOException {
123123
String docId = "version_conflict";
124124
highLevelClient().index(
125125
new IndexRequest("index", "_doc", docId).source(Collections.singletonMap("foo", "bar")), RequestOptions.DEFAULT);
126-
DeleteRequest deleteRequest = new DeleteRequest("index", "_doc", docId).version(2);
126+
DeleteRequest deleteRequest = new DeleteRequest("index", docId).version(2);
127127
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
128128
() -> execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync));
129129
assertEquals(RestStatus.CONFLICT, exception.status());
@@ -137,7 +137,7 @@ public void testDelete() throws IOException {
137137
highLevelClient().index(
138138
new IndexRequest("index", "_doc", docId).source(Collections.singletonMap("foo", "bar"))
139139
.versionType(VersionType.EXTERNAL).version(12), RequestOptions.DEFAULT);
140-
DeleteRequest deleteRequest = new DeleteRequest("index", "_doc", docId).versionType(VersionType.EXTERNAL).version(13);
140+
DeleteRequest deleteRequest = new DeleteRequest("index", docId).versionType(VersionType.EXTERNAL).version(13);
141141
DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync);
142142
assertEquals("index", deleteResponse.getIndex());
143143
assertEquals("_doc", deleteResponse.getType());
@@ -151,7 +151,7 @@ public void testDelete() throws IOException {
151151
new IndexRequest("index", "_doc", docId).source(Collections.singletonMap("foo", "bar"))
152152
.versionType(VersionType.EXTERNAL).version(12), RequestOptions.DEFAULT);
153153
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> {
154-
DeleteRequest deleteRequest = new DeleteRequest("index", "_doc", docId).versionType(VersionType.EXTERNAL).version(10);
154+
DeleteRequest deleteRequest = new DeleteRequest("index", docId).versionType(VersionType.EXTERNAL).version(10);
155155
execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync);
156156
});
157157
assertEquals(RestStatus.CONFLICT, exception.status());
@@ -164,7 +164,7 @@ public void testDelete() throws IOException {
164164
String docId = "routing";
165165
highLevelClient().index(new IndexRequest("index", "_doc", docId).source(Collections.singletonMap("foo", "bar")).routing("foo"),
166166
RequestOptions.DEFAULT);
167-
DeleteRequest deleteRequest = new DeleteRequest("index", "_doc", docId).routing("foo");
167+
DeleteRequest deleteRequest = new DeleteRequest("index", docId).routing("foo");
168168
DeleteResponse deleteResponse = execute(deleteRequest, highLevelClient()::delete, highLevelClient()::deleteAsync);
169169
assertEquals("index", deleteResponse.getIndex());
170170
assertEquals("_doc", deleteResponse.getType());
@@ -666,7 +666,7 @@ public void testBulk() throws IOException {
666666
highLevelClient().index(
667667
new IndexRequest("index", "_doc", id).source("field", -1), RequestOptions.DEFAULT).status());
668668
}
669-
DeleteRequest deleteRequest = new DeleteRequest("index", "_doc", id);
669+
DeleteRequest deleteRequest = new DeleteRequest("index", id);
670670
bulkRequest.add(deleteRequest);
671671

672672
} else {
@@ -977,7 +977,7 @@ public void afterBulk(long executionId, BulkRequest request, Throwable failure)
977977
highLevelClient().index(
978978
new IndexRequest("index", "_doc", id).source("field", -1), RequestOptions.DEFAULT).status());
979979
}
980-
DeleteRequest deleteRequest = new DeleteRequest("index", "_doc", id);
980+
DeleteRequest deleteRequest = new DeleteRequest("index", id);
981981
processor.add(deleteRequest);
982982

983983
} else {

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,7 @@ public void testDelete() throws Exception {
563563
// tag::delete-request
564564
DeleteRequest request = new DeleteRequest(
565565
"posts", // <1>
566-
"_doc", // <2>
567-
"1"); // <3>
566+
"1"); // <2>
568567
// end::delete-request
569568

570569
// tag::delete-execute
@@ -575,7 +574,6 @@ public void testDelete() throws Exception {
575574

576575
// tag::delete-response
577576
String index = deleteResponse.getIndex();
578-
String type = deleteResponse.getType();
579577
String id = deleteResponse.getId();
580578
long version = deleteResponse.getVersion();
581579
ReplicationResponse.ShardInfo shardInfo = deleteResponse.getShardInfo();
@@ -592,7 +590,7 @@ public void testDelete() throws Exception {
592590
}
593591

594592
{
595-
DeleteRequest request = new DeleteRequest("posts", "_doc", "1");
593+
DeleteRequest request = new DeleteRequest("posts", "1");
596594
// tag::delete-request-routing
597595
request.routing("routing"); // <1>
598596
// end::delete-request-routing
@@ -614,7 +612,7 @@ public void testDelete() throws Exception {
614612

615613
{
616614
// tag::delete-notfound
617-
DeleteRequest request = new DeleteRequest("posts", "_doc", "does_not_exist");
615+
DeleteRequest request = new DeleteRequest("posts", "does_not_exist");
618616
DeleteResponse deleteResponse = client.delete(
619617
request, RequestOptions.DEFAULT);
620618
if (deleteResponse.getResult() == DocWriteResponse.Result.NOT_FOUND) {
@@ -631,7 +629,7 @@ public void testDelete() throws Exception {
631629
// tag::delete-conflict
632630
try {
633631
DeleteResponse deleteResponse = client.delete(
634-
new DeleteRequest("posts", "_doc", "1").version(2),
632+
new DeleteRequest("posts", "1").version(2),
635633
RequestOptions.DEFAULT);
636634
} catch (ElasticsearchException exception) {
637635
if (exception.status() == RestStatus.CONFLICT) {
@@ -645,7 +643,7 @@ public void testDelete() throws Exception {
645643
RequestOptions.DEFAULT);
646644
assertSame(RestStatus.CREATED, indexResponse.status());
647645

648-
DeleteRequest request = new DeleteRequest("posts", "_doc", "async");
646+
DeleteRequest request = new DeleteRequest("posts", "async");
649647

650648
ActionListener<DeleteResponse> listener;
651649
// tag::delete-execute-listener
@@ -696,7 +694,7 @@ public void testBulk() throws Exception {
696694
{
697695
// tag::bulk-request-with-mixed-operations
698696
BulkRequest request = new BulkRequest();
699-
request.add(new DeleteRequest("posts", "_doc", "3")); // <1>
697+
request.add(new DeleteRequest("posts", "3")); // <1>
700698
request.add(new UpdateRequest("posts", "_doc", "2") // <2>
701699
.doc(XContentType.JSON,"other", "test"));
702700
request.add(new IndexRequest("posts", "_doc", "4") // <3>

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MigrationDocumentationIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void testRequests() throws Exception {
8282
RestHighLevelClient client = highLevelClient();
8383
{
8484
//tag::migration-request-ctor
85-
IndexRequest request = new IndexRequest("index", "doc", "id"); // <1>
85+
IndexRequest request = new IndexRequest("index", "_doc", "id"); // <1>
8686
request.source("{\"field\":\"value\"}", XContentType.JSON);
8787
//end::migration-request-ctor
8888

@@ -93,7 +93,7 @@ public void testRequests() throws Exception {
9393
}
9494
{
9595
//tag::migration-request-async-execution
96-
DeleteRequest request = new DeleteRequest("index", "doc", "id"); // <1>
96+
DeleteRequest request = new DeleteRequest("index", "id"); // <1>
9797
client.deleteAsync(request, RequestOptions.DEFAULT, new ActionListener<DeleteResponse>() { // <2>
9898
@Override
9999
public void onResponse(DeleteResponse deleteResponse) {
@@ -106,11 +106,11 @@ public void onFailure(Exception e) {
106106
}
107107
});
108108
//end::migration-request-async-execution
109-
assertBusy(() -> assertFalse(client.exists(new GetRequest("index", "doc", "id"), RequestOptions.DEFAULT)));
109+
assertBusy(() -> assertFalse(client.exists(new GetRequest("index", "_doc", "id"), RequestOptions.DEFAULT)));
110110
}
111111
{
112112
//tag::migration-request-sync-execution
113-
DeleteRequest request = new DeleteRequest("index", "doc", "id");
113+
DeleteRequest request = new DeleteRequest("index", "id");
114114
DeleteResponse response = client.delete(request, RequestOptions.DEFAULT); // <1>
115115
//end::migration-request-sync-execution
116116
assertEquals(RestStatus.NOT_FOUND, response.status());

docs/java-rest/high-level/document/delete.asciidoc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
[id="{upid}-{api}-request"]
1111
==== Delete Request
1212

13-
A +{request}+ has no arguments
13+
A +{request}+ has two required arguments:
1414

1515
["source","java",subs="attributes,callouts,macros"]
1616
--------------------------------------------------
1717
include-tagged::{doc-tests-file}[{api}-request]
1818
--------------------------------------------------
1919
<1> Index
20-
<2> Type
21-
<3> Document id
20+
<2> Document id
2221

2322
==== Optional arguments
2423
The following arguments can optionally be provided:

docs/reference/docs/delete.asciidoc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[[docs-delete]]
22
== Delete API
33

4-
The delete API allows to delete a typed JSON document from a specific
4+
The delete API allows to delete a JSON document from a specific
55
index based on its id. The following example deletes the JSON document
6-
from an index called `twitter`, under a type called `_doc`, with id `1`:
6+
from an index called `twitter` with ID `1`:
77

88
[source,js]
99
--------------------------------------------------
@@ -92,10 +92,7 @@ the request.
9292
If an <<docs-index_,external versioning variant>> is used,
9393
the delete operation automatically creates an index if it has not been
9494
created before (check out the <<indices-create-index,create index API>>
95-
for manually creating an index), and also automatically creates a
96-
dynamic type mapping for the specific type if it has not been created
97-
before (check out the <<indices-put-mapping,put mapping>>
98-
API for manually creating type mapping).
95+
for manually creating an index).
9996

10097
[float]
10198
[[delete-distributed]]

rest-api-spec/src/main/resources/rest-api-spec/api/delete.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete.html",
44
"methods": ["DELETE"],
55
"url": {
6-
"path": "/{index}/{type}/{id}",
6+
"path": "/{index}/_doc/{id}",
77
"paths": ["/{index}/{type}/{id}", "/{index}/_doc/{id}"],
88
"parts": {
99
"id": {

server/src/main/java/org/elasticsearch/action/DocWriteResponse.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ public ShardId getShardId() {
156156

157157
/**
158158
* The type of the document changed.
159+
*
160+
* @deprecated Types are in the process of being removed.
159161
*/
162+
@Deprecated
160163
public String getType() {
161164
return this.type;
162165
}

server/src/main/java/org/elasticsearch/action/delete/DeleteRequest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.common.io.stream.StreamOutput;
3131
import org.elasticsearch.common.lucene.uid.Versions;
3232
import org.elasticsearch.index.VersionType;
33+
import org.elasticsearch.index.mapper.MapperService;
3334
import org.elasticsearch.index.shard.ShardId;
3435

3536
import java.io.IOException;
@@ -50,7 +51,7 @@
5051
public class DeleteRequest extends ReplicatedWriteRequest<DeleteRequest>
5152
implements DocWriteRequest<DeleteRequest>, CompositeIndicesRequest {
5253

53-
private String type;
54+
private String type = MapperService.SINGLE_MAPPING_NAME;
5455
private String id;
5556
@Nullable
5657
private String routing;
@@ -74,13 +75,27 @@ public DeleteRequest(String index) {
7475
* @param index The index to get the document from
7576
* @param type The type of the document
7677
* @param id The id of the document
78+
*
79+
* @deprecated Types are in the process of being removed. Use {@link #DeleteRequest(String, String)} instead.
7780
*/
81+
@Deprecated
7882
public DeleteRequest(String index, String type, String id) {
7983
this.index = index;
8084
this.type = type;
8185
this.id = id;
8286
}
8387

88+
/**
89+
* Constructs a new delete request against the specified index and id.
90+
*
91+
* @param index The index to get the document from
92+
* @param id The id of the document
93+
*/
94+
public DeleteRequest(String index, String id) {
95+
this.index = index;
96+
this.id = id;
97+
}
98+
8499
@Override
85100
public ActionRequestValidationException validate() {
86101
ActionRequestValidationException validationException = super.validate();
@@ -102,15 +117,21 @@ public ActionRequestValidationException validate() {
102117

103118
/**
104119
* The type of the document to delete.
120+
*
121+
* @deprecated Types are in the process of being removed.
105122
*/
123+
@Deprecated
106124
@Override
107125
public String type() {
108126
return type;
109127
}
110128

111129
/**
112130
* Sets the type of the document to delete.
131+
*
132+
* @deprecated Types are in the process of being removed.
113133
*/
134+
@Deprecated
114135
@Override
115136
public DeleteRequest type(String type) {
116137
this.type = type;

server/src/main/java/org/elasticsearch/action/get/GetResponse.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ public DocumentField getField(String name) {
149149
* @deprecated Use {@link GetResponse#getSource()} instead
150150
*/
151151
@Deprecated
152-
@Override
153152
public Iterator<DocumentField> iterator() {
154153
return getResult.iterator();
155154
}

server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919

2020
package org.elasticsearch.rest.action.document;
2121

22+
import org.apache.logging.log4j.LogManager;
2223
import org.elasticsearch.action.delete.DeleteRequest;
2324
import org.elasticsearch.action.support.ActiveShardCount;
2425
import org.elasticsearch.client.node.NodeClient;
26+
import org.elasticsearch.common.logging.DeprecationLogger;
2527
import org.elasticsearch.common.settings.Settings;
2628
import org.elasticsearch.index.VersionType;
29+
import org.elasticsearch.index.mapper.MapperService;
2730
import org.elasticsearch.rest.BaseRestHandler;
2831
import org.elasticsearch.rest.RestController;
2932
import org.elasticsearch.rest.RestRequest;
@@ -35,6 +38,11 @@
3538
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
3639

3740
public class RestDeleteAction extends BaseRestHandler {
41+
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(
42+
LogManager.getLogger(RestDeleteAction.class));
43+
static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in " +
44+
"document index requests is deprecated, use the /{index}/_doc/{id} endpoint instead.";
45+
3846
public RestDeleteAction(Settings settings, RestController controller) {
3947
super(settings);
4048
controller.registerHandler(DELETE, "/{index}/{type}/{id}", this);
@@ -47,9 +55,12 @@ public String getName() {
4755

4856
@Override
4957
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
50-
DeleteRequest deleteRequest = new DeleteRequest(request.param("index"),
51-
request.param("type"),
52-
request.param("id"));
58+
String type = request.param("type");
59+
if (!type.equals(MapperService.SINGLE_MAPPING_NAME)) {
60+
deprecationLogger.deprecated(TYPES_DEPRECATION_MESSAGE);
61+
}
62+
63+
DeleteRequest deleteRequest = new DeleteRequest(request.param("index"), type, request.param("id"));
5364
deleteRequest.routing(request.param("routing"));
5465
deleteRequest.timeout(request.paramAsTime("timeout", DeleteRequest.DEFAULT_TIMEOUT));
5566
deleteRequest.setRefreshPolicy(request.param("refresh"));

0 commit comments

Comments
 (0)