Skip to content

Commit 7c90801

Browse files
authored
Remove types from Get/MultiGet (#46587)
This commit removes types from the ShardGetService, and propagates this API change up through the Transport and Rest actions for Get and MultiGet Relates to #41059
1 parent 42bf8a0 commit 7c90801

File tree

233 files changed

+728
-3015
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+728
-3015
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static Request get(GetRequest getRequest) {
266266
}
267267

268268
private static Request getStyleRequest(String method, GetRequest getRequest) {
269-
Request request = new Request(method, endpoint(getRequest.index(), getRequest.type(), getRequest.id()));
269+
Request request = new Request(method, endpoint(getRequest.index(), getRequest.id()));
270270

271271
Params parameters = new Params();
272272
parameters.withPreference(getRequest.preference());
@@ -282,13 +282,7 @@ private static Request getStyleRequest(String method, GetRequest getRequest) {
282282
}
283283

284284
static Request sourceExists(GetRequest getRequest) {
285-
String optionalType = getRequest.type();
286-
String endpoint;
287-
if (optionalType.equals(MapperService.SINGLE_MAPPING_NAME)) {
288-
endpoint = endpoint(getRequest.index(), "_source", getRequest.id());
289-
} else {
290-
endpoint = endpoint(getRequest.index(), optionalType, getRequest.id(), "_source");
291-
}
285+
String endpoint = endpoint(getRequest.index(), "_source", getRequest.id());
292286
Request request = new Request(HttpHead.METHOD_NAME, endpoint);
293287
Params parameters = new Params();
294288
parameters.withPreference(getRequest.preference());
@@ -742,6 +736,10 @@ static String endpoint(String index, String type, String id) {
742736
return new EndpointBuilder().addPathPart(index, type, id).build();
743737
}
744738

739+
static String endpoint(String index, String id) {
740+
return new EndpointBuilder().addPathPart(index, "_doc", id).build();
741+
}
742+
745743
@Deprecated
746744
static String endpoint(String index, String type, String id, String endpoint) {
747745
return new EndpointBuilder().addPathPart(index, type, id).addPathPartAsIs(endpoint).build();

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,11 @@ private static BytesArray bytesBulkRequest(String localIndex, String localType,
483483
private MultiGetRequest indexDocs(BulkProcessor processor, int numDocs) throws Exception {
484484
return indexDocs(processor, numDocs, "test", null, null, null, null);
485485
}
486-
486+
487487
private static void assertResponseItems(List<BulkItemResponse> bulkItemResponses, int numDocs) {
488488
assertResponseItems(bulkItemResponses, numDocs, MapperService.SINGLE_MAPPING_NAME);
489489
}
490-
490+
491491
private static void assertResponseItems(List<BulkItemResponse> bulkItemResponses, int numDocs, String expectedType) {
492492
assertThat(bulkItemResponses.size(), is(numDocs));
493493
int i = 1;
@@ -505,7 +505,6 @@ private static void assertMultiGetResponse(MultiGetResponse multiGetResponse, in
505505
int i = 1;
506506
for (MultiGetItemResponse multiGetItemResponse : multiGetResponse) {
507507
assertThat(multiGetItemResponse.getIndex(), equalTo("test"));
508-
assertThat(multiGetItemResponse.getType(), equalTo("_doc"));
509508
assertThat(multiGetItemResponse.getId(), equalTo(Integer.toString(i++)));
510509
}
511510
}

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

+1-45
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@
5656
import org.elasticsearch.rest.RestStatus;
5757
import org.elasticsearch.rest.action.document.RestBulkAction;
5858
import org.elasticsearch.rest.action.document.RestDeleteAction;
59-
import org.elasticsearch.rest.action.document.RestGetAction;
6059
import org.elasticsearch.rest.action.document.RestIndexAction;
61-
import org.elasticsearch.rest.action.document.RestMultiGetAction;
6260
import org.elasticsearch.rest.action.document.RestUpdateAction;
6361
import org.elasticsearch.script.Script;
6462
import org.elasticsearch.script.ScriptType;
@@ -293,7 +291,6 @@ public void testGet() throws IOException {
293291
}
294292
GetResponse getResponse = execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync);
295293
assertEquals("index", getResponse.getIndex());
296-
assertEquals("_doc", getResponse.getType());
297294
assertEquals("id", getResponse.getId());
298295
assertTrue(getResponse.isExists());
299296
assertFalse(getResponse.isSourceEmpty());
@@ -304,7 +301,6 @@ public void testGet() throws IOException {
304301
GetRequest getRequest = new GetRequest("index", "does_not_exist");
305302
GetResponse getResponse = execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync);
306303
assertEquals("index", getResponse.getIndex());
307-
assertEquals("_doc", getResponse.getType());
308304
assertEquals("does_not_exist", getResponse.getId());
309305
assertFalse(getResponse.isExists());
310306
assertEquals(-1, getResponse.getVersion());
@@ -316,7 +312,6 @@ public void testGet() throws IOException {
316312
getRequest.fetchSourceContext(new FetchSourceContext(false, Strings.EMPTY_ARRAY, Strings.EMPTY_ARRAY));
317313
GetResponse getResponse = execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync);
318314
assertEquals("index", getResponse.getIndex());
319-
assertEquals("_doc", getResponse.getType());
320315
assertEquals("id", getResponse.getId());
321316
assertTrue(getResponse.isExists());
322317
assertTrue(getResponse.isSourceEmpty());
@@ -332,7 +327,6 @@ public void testGet() throws IOException {
332327
}
333328
GetResponse getResponse = execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync);
334329
assertEquals("index", getResponse.getIndex());
335-
assertEquals("_doc", getResponse.getType());
336330
assertEquals("id", getResponse.getId());
337331
assertTrue(getResponse.isExists());
338332
assertFalse(getResponse.isSourceEmpty());
@@ -353,21 +347,6 @@ public void testGetWithTypes() throws IOException {
353347
highLevelClient()::indexAsync,
354348
expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE)
355349
);
356-
357-
GetRequest getRequest = new GetRequest("index", "type", "id");
358-
GetResponse getResponse = execute(getRequest,
359-
highLevelClient()::get,
360-
highLevelClient()::getAsync,
361-
expectWarnings(RestGetAction.TYPES_DEPRECATION_MESSAGE));
362-
363-
assertEquals("index", getResponse.getIndex());
364-
assertEquals("type", getResponse.getType());
365-
assertEquals("id", getResponse.getId());
366-
367-
assertTrue(getResponse.isExists());
368-
assertFalse(getResponse.isSourceEmpty());
369-
assertEquals(1L, getResponse.getVersion());
370-
assertEquals(document, getResponse.getSourceAsString());
371350
}
372351

373352
public void testMultiGet() throws IOException {
@@ -381,15 +360,13 @@ public void testMultiGet() throws IOException {
381360
assertTrue(response.getResponses()[0].isFailed());
382361
assertNull(response.getResponses()[0].getResponse());
383362
assertEquals("id1", response.getResponses()[0].getFailure().getId());
384-
assertNull(response.getResponses()[0].getFailure().getType());
385363
assertEquals("index", response.getResponses()[0].getFailure().getIndex());
386364
assertEquals("Elasticsearch exception [type=index_not_found_exception, reason=no such index [index]]",
387365
response.getResponses()[0].getFailure().getFailure().getMessage());
388366

389367
assertTrue(response.getResponses()[1].isFailed());
390368
assertNull(response.getResponses()[1].getResponse());
391369
assertEquals("id2", response.getResponses()[1].getId());
392-
assertNull(response.getResponses()[1].getType());
393370
assertEquals("index", response.getResponses()[1].getIndex());
394371
assertEquals("Elasticsearch exception [type=index_not_found_exception, reason=no such index [index]]",
395372
response.getResponses()[1].getFailure().getFailure().getMessage());
@@ -413,14 +390,12 @@ public void testMultiGet() throws IOException {
413390
assertFalse(response.getResponses()[0].isFailed());
414391
assertNull(response.getResponses()[0].getFailure());
415392
assertEquals("id1", response.getResponses()[0].getId());
416-
assertEquals("_doc", response.getResponses()[0].getType());
417393
assertEquals("index", response.getResponses()[0].getIndex());
418394
assertEquals(Collections.singletonMap("field", "value1"), response.getResponses()[0].getResponse().getSource());
419395

420396
assertFalse(response.getResponses()[1].isFailed());
421397
assertNull(response.getResponses()[1].getFailure());
422398
assertEquals("id2", response.getResponses()[1].getId());
423-
assertEquals("_doc", response.getResponses()[1].getType());
424399
assertEquals("index", response.getResponses()[1].getIndex());
425400
assertEquals(Collections.singletonMap("field", "value2"), response.getResponses()[1].getResponse().getSource());
426401
}
@@ -437,23 +412,7 @@ public void testMultiGetWithTypes() throws IOException {
437412
highLevelClient().bulk(bulk, expectWarnings(RestBulkAction.TYPES_DEPRECATION_MESSAGE));
438413
MultiGetRequest multiGetRequest = new MultiGetRequest();
439414
multiGetRequest.add("index", "id1");
440-
multiGetRequest.add("index", "type", "id2");
441-
442-
MultiGetResponse response = execute(multiGetRequest,
443-
highLevelClient()::mget,
444-
highLevelClient()::mgetAsync,
445-
expectWarnings(RestMultiGetAction.TYPES_DEPRECATION_MESSAGE));
446-
assertEquals(2, response.getResponses().length);
447-
448-
GetResponse firstResponse = response.getResponses()[0].getResponse();
449-
assertEquals("index", firstResponse.getIndex());
450-
assertEquals("type", firstResponse.getType());
451-
assertEquals("id1", firstResponse.getId());
452-
453-
GetResponse secondResponse = response.getResponses()[1].getResponse();
454-
assertEquals("index", secondResponse.getIndex());
455-
assertEquals("type", secondResponse.getType());
456-
assertEquals("id2", secondResponse.getId());
415+
multiGetRequest.add("index", "id2");
457416
}
458417

459418
public void testIndex() throws IOException {
@@ -972,7 +931,6 @@ public void testUrlEncode() throws IOException {
972931
GetResponse getResponse = highLevelClient().get(getRequest, RequestOptions.DEFAULT);
973932
assertTrue(getResponse.isExists());
974933
assertEquals(expectedIndex, getResponse.getIndex());
975-
assertEquals("_doc", getResponse.getType());
976934
assertEquals("id#1", getResponse.getId());
977935
}
978936

@@ -990,7 +948,6 @@ public void testUrlEncode() throws IOException {
990948
GetResponse getResponse = highLevelClient().get(getRequest, RequestOptions.DEFAULT);
991949
assertTrue(getResponse.isExists());
992950
assertEquals("index", getResponse.getIndex());
993-
assertEquals("_doc", getResponse.getType());
994951
assertEquals(docId, getResponse.getId());
995952
}
996953

@@ -1014,7 +971,6 @@ public void testParamsEncode() throws IOException {
1014971
GetResponse getResponse = highLevelClient().get(getRequest, RequestOptions.DEFAULT);
1015972
assertTrue(getResponse.isExists());
1016973
assertEquals("index", getResponse.getIndex());
1017-
assertEquals("_doc", getResponse.getType());
1018974
assertEquals("id", getResponse.getId());
1019975
assertEquals(routing, getResponse.getField("_routing").getValue());
1020976
}

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

+4-19
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,13 @@ public void testGet() {
152152
getAndExistsTest(RequestConverters::get, HttpGet.METHOD_NAME);
153153
}
154154

155-
public void testGetWithType() {
156-
getAndExistsWithTypeTest(RequestConverters::get, HttpGet.METHOD_NAME);
157-
}
158-
159155
public void testSourceExists() throws IOException {
160156
doTestSourceExists((index, id) -> new GetRequest(index, id));
161157
}
162158

163159
public void testSourceExistsWithType() throws IOException {
164160
String type = frequently() ? randomAlphaOfLengthBetween(3, 10) : MapperService.SINGLE_MAPPING_NAME;
165-
doTestSourceExists((index, id) -> new GetRequest(index, type, id));
161+
doTestSourceExists((index, id) -> new GetRequest(index, id));
166162
}
167163

168164
private static void doTestSourceExists(BiFunction<String, String, GetRequest> requestFunction) throws IOException {
@@ -197,12 +193,7 @@ private static void doTestSourceExists(BiFunction<String, String, GetRequest> re
197193
}
198194
Request request = RequestConverters.sourceExists(getRequest);
199195
assertEquals(HttpHead.METHOD_NAME, request.getMethod());
200-
String type = getRequest.type();
201-
if (type.equals(MapperService.SINGLE_MAPPING_NAME)) {
202-
assertEquals("/" + index + "/_source/" + id, request.getEndpoint());
203-
} else {
204-
assertEquals("/" + index + "/" + type + "/" + id + "/_source", request.getEndpoint());
205-
}
196+
assertEquals("/" + index + "/_source/" + id, request.getEndpoint());
206197

207198
assertEquals(expectedParams, request.getParameters());
208199
assertNull(request.getEntity());
@@ -260,7 +251,6 @@ public void testMultiGet() throws IOException {
260251
public void testMultiGetWithType() throws IOException {
261252
MultiGetRequest multiGetRequest = new MultiGetRequest();
262253
MultiGetRequest.Item item = new MultiGetRequest.Item(randomAlphaOfLength(4),
263-
randomAlphaOfLength(4),
264254
randomAlphaOfLength(4));
265255
multiGetRequest.add(item);
266256

@@ -314,10 +304,6 @@ public void testExists() {
314304
getAndExistsTest(RequestConverters::exists, HttpHead.METHOD_NAME);
315305
}
316306

317-
public void testExistsWithType() {
318-
getAndExistsWithTypeTest(RequestConverters::exists, HttpHead.METHOD_NAME);
319-
}
320-
321307
private static void getAndExistsTest(Function<GetRequest, Request> requestConverter, String method) {
322308
String index = randomAlphaOfLengthBetween(3, 10);
323309
String id = randomAlphaOfLengthBetween(3, 10);
@@ -377,12 +363,11 @@ private static void getAndExistsTest(Function<GetRequest, Request> requestConver
377363

378364
private static void getAndExistsWithTypeTest(Function<GetRequest, Request> requestConverter, String method) {
379365
String index = randomAlphaOfLengthBetween(3, 10);
380-
String type = randomAlphaOfLengthBetween(3, 10);
381366
String id = randomAlphaOfLengthBetween(3, 10);
382-
GetRequest getRequest = new GetRequest(index, type, id);
367+
GetRequest getRequest = new GetRequest(index, id);
383368

384369
Request request = requestConverter.apply(getRequest);
385-
assertEquals("/" + index + "/" + type + "/" + id, request.getEndpoint());
370+
assertEquals("/" + index + "/" + id, request.getEndpoint());
386371
assertNull(request.getEntity());
387372
assertEquals(method, request.getMethod());
388373
}

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

-1
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,6 @@ private MultiGetItemResponse unwrapAndAssertExample(MultiGetResponse response) {
19431943
assertThat(response.getResponses(), arrayWithSize(1));
19441944
MultiGetItemResponse item = response.getResponses()[0];
19451945
assertEquals("index", item.getIndex());
1946-
assertEquals("_doc", item.getType());
19471946
assertEquals("example_id", item.getId());
19481947
return item;
19491948
}

docs/plugins/ingest-attachment.asciidoc

-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ Returns this:
5959
{
6060
"found": true,
6161
"_index": "my_index",
62-
"_type": "_doc",
6362
"_id": "my_id",
6463
"_version": 1,
6564
"_seq_no": 22,
@@ -142,7 +141,6 @@ Returns this:
142141
{
143142
"found": true,
144143
"_index": "my_index",
145-
"_type": "_doc",
146144
"_id": "my_id",
147145
"_version": 1,
148146
"_seq_no": 35,
@@ -191,7 +189,6 @@ Returns this:
191189
{
192190
"found": true,
193191
"_index": "my_index",
194-
"_type": "_doc",
195192
"_id": "my_id_2",
196193
"_version": 1,
197194
"_seq_no": 40,
@@ -284,7 +281,6 @@ Returns this:
284281
--------------------------------------------------
285282
{
286283
"_index" : "my_index",
287-
"_type" : "_doc",
288284
"_id" : "my_id",
289285
"_version" : 1,
290286
"_seq_no" : 50,

docs/reference/docs/concurrency-control.asciidoc

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ You can see the assigned sequence number and primary term in the
4141
"successful" : 1
4242
},
4343
"_index" : "products",
44-
"_type" : "_doc",
4544
"_id" : "1567",
45+
"_type" : "_doc",
4646
"_version" : 1,
4747
"_seq_no" : 362,
4848
"_primary_term" : 2,
@@ -69,7 +69,6 @@ returns:
6969
--------------------------------------------------
7070
{
7171
"_index" : "products",
72-
"_type" : "_doc",
7372
"_id" : "1567",
7473
"_version" : 1,
7574
"_seq_no" : 362,

docs/reference/docs/get.asciidoc

-6
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@ include::{docdir}/rest-api/common-parms.asciidoc[tag=version_type]
189189
`_index`::
190190
The name of the index the document belongs to.
191191

192-
`_type`::
193-
The document type. {es} indices now support a single document type, `_doc`.
194-
195192
`_id`::
196193
The unique identifier for the document.
197194

@@ -239,7 +236,6 @@ The API returns the following result:
239236
--------------------------------------------------
240237
{
241238
"_index" : "twitter",
242-
"_type" : "_doc",
243239
"_id" : "0",
244240
"_version" : 1,
245241
"_seq_no" : 10,
@@ -351,7 +347,6 @@ The API returns the following result:
351347
--------------------------------------------------
352348
{
353349
"_index": "twitter",
354-
"_type": "_doc",
355350
"_id": "1",
356351
"_version": 1,
357352
"_seq_no" : 22,
@@ -393,7 +388,6 @@ The API returns the following result:
393388
--------------------------------------------------
394389
{
395390
"_index": "twitter",
396-
"_type": "_doc",
397391
"_id": "2",
398392
"_version": 1,
399393
"_seq_no" : 13,

0 commit comments

Comments
 (0)