Skip to content

Commit 0e1ddfd

Browse files
authored
Deprecate types in document delete requests. (#36087)
* Make sure to use _doc as a type name in the CRUD HLRC tests. * Deprecate types in document delete requests.
1 parent 7b999bd commit 0e1ddfd

File tree

13 files changed

+311
-212
lines changed

13 files changed

+311
-212
lines changed

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

Lines changed: 117 additions & 117 deletions
Large diffs are not rendered by default.

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

Lines changed: 68 additions & 70 deletions
Large diffs are not rendered by default.

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]]

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ public void testIndexing() throws IOException {
129129

130130
if (CLUSTER_TYPE != ClusterType.OLD) {
131131
bulk("test_index", "_" + CLUSTER_TYPE, 5);
132-
Request toBeDeleted = new Request("PUT", "/test_index/doc/to_be_deleted");
132+
Request toBeDeleted = new Request("PUT", "/test_index/_doc/to_be_deleted");
133133
toBeDeleted.addParameter("refresh", "true");
134134
toBeDeleted.setJsonEntity("{\"f1\": \"delete-me\"}");
135135
client().performRequest(toBeDeleted);
136136
assertCount("test_index", expectedCount + 6);
137137

138-
Request delete = new Request("DELETE", "/test_index/doc/to_be_deleted");
138+
Request delete = new Request("DELETE", "/test_index/_doc/to_be_deleted");
139139
delete.addParameter("refresh", "true");
140140
client().performRequest(delete);
141141

@@ -146,7 +146,7 @@ public void testIndexing() throws IOException {
146146
private void bulk(String index, String valueSuffix, int count) throws IOException {
147147
StringBuilder b = new StringBuilder();
148148
for (int i = 0; i < count; i++) {
149-
b.append("{\"index\": {\"_index\": \"").append(index).append("\", \"_type\": \"doc\"}}\n");
149+
b.append("{\"index\": {\"_index\": \"").append(index).append("\", \"_type\": \"_doc\"}}\n");
150150
b.append("{\"f1\": \"v").append(i).append(valueSuffix).append("\", \"f2\": ").append(i).append("}\n");
151151
}
152152
Request bulk = new Request("POST", "/_bulk");

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
}

0 commit comments

Comments
 (0)