Skip to content

Commit 99f89cd

Browse files
authored
Deprecate types in get, exists, and multi get. (#35930)
For each API, the following updates were made: - Add deprecation warnings to `Rest*Action`, plus tests in `Rest*ActionTests`. - For each REST yml test, make sure there is one version without types, and another legacy version that retains types (called *_with_types.yml). - Deprecate relevant methods on the Java HLRC requests/ responses. - Update documentation (for both the REST API and Java HLRC).
1 parent b030125 commit 99f89cd

File tree

53 files changed

+1256
-258
lines changed

Some content is hidden

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

53 files changed

+1256
-258
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public void testBulkProcessorConcurrentRequests() throws Exception {
163163
for (BulkItemResponse bulkItemResponse : listener.bulkItems) {
164164
assertThat(bulkItemResponse.getFailureMessage(), bulkItemResponse.isFailed(), equalTo(false));
165165
assertThat(bulkItemResponse.getIndex(), equalTo("test"));
166-
assertThat(bulkItemResponse.getType(), equalTo("test"));
166+
assertThat(bulkItemResponse.getType(), equalTo("_doc"));
167167
//with concurrent requests > 1 we can't rely on the order of the bulk requests
168168
assertThat(Integer.valueOf(bulkItemResponse.getId()), both(greaterThan(0)).and(lessThanOrEqualTo(numDocs)));
169169
//we do want to check that we don't get duplicate ids back
@@ -240,12 +240,12 @@ public void testBulkProcessorConcurrentRequestsReadOnlyIndex() throws Exception
240240
for (int i = 1; i <= numDocs; i++) {
241241
if (randomBoolean()) {
242242
testDocs++;
243-
processor.add(new IndexRequest("test", "test", Integer.toString(testDocs))
243+
processor.add(new IndexRequest("test", "_doc", Integer.toString(testDocs))
244244
.source(XContentType.JSON, "field", "value"));
245-
multiGetRequest.add("test", "test", Integer.toString(testDocs));
245+
multiGetRequest.add("test", Integer.toString(testDocs));
246246
} else {
247247
testReadOnlyDocs++;
248-
processor.add(new IndexRequest("test-ro", "test", Integer.toString(testReadOnlyDocs))
248+
processor.add(new IndexRequest("test-ro", "_doc", Integer.toString(testReadOnlyDocs))
249249
.source(XContentType.JSON, "field", "value"));
250250
}
251251
}
@@ -262,7 +262,7 @@ public void testBulkProcessorConcurrentRequestsReadOnlyIndex() throws Exception
262262
Set<String> readOnlyIds = new HashSet<>();
263263
for (BulkItemResponse bulkItemResponse : listener.bulkItems) {
264264
assertThat(bulkItemResponse.getIndex(), either(equalTo("test")).or(equalTo("test-ro")));
265-
assertThat(bulkItemResponse.getType(), equalTo("test"));
265+
assertThat(bulkItemResponse.getType(), equalTo("_doc"));
266266
if (bulkItemResponse.getIndex().equals("test")) {
267267
assertThat(bulkItemResponse.isFailed(), equalTo(false));
268268
//with concurrent requests > 1 we can't rely on the order of the bulk requests
@@ -330,12 +330,12 @@ public void testGlobalParametersAndBulkProcessor() throws Exception {
330330
.setConcurrentRequests(randomIntBetween(0, 1)).setBulkActions(numDocs)
331331
.setFlushInterval(TimeValue.timeValueHours(24)).setBulkSize(new ByteSizeValue(1, ByteSizeUnit.GB))
332332
.setGlobalIndex("test")
333-
.setGlobalType("test")
333+
.setGlobalType("_doc")
334334
.setGlobalRouting("routing")
335335
.setGlobalPipeline("pipeline_id")
336336
.build()) {
337337

338-
indexDocs(processor, numDocs, null, null, "test", "test", "pipeline_id");
338+
indexDocs(processor, numDocs, null, null, "test", "pipeline_id");
339339
latch.await();
340340

341341
assertThat(listener.beforeCounts.get(), equalTo(1));
@@ -346,7 +346,7 @@ public void testGlobalParametersAndBulkProcessor() throws Exception {
346346
Iterable<SearchHit> hits = searchAll(new SearchRequest("test").routing("routing"));
347347

348348
assertThat(hits, everyItem(hasProperty(fieldFromSource("fieldNameXYZ"), equalTo("valueXYZ"))));
349-
assertThat(hits, everyItem(Matchers.allOf(hasIndex("test"), hasType("test"))));
349+
assertThat(hits, everyItem(Matchers.allOf(hasIndex("test"), hasType("_doc"))));
350350
assertThat(hits, containsInAnyOrder(expectedIds(numDocs)));
351351
}
352352
}
@@ -359,18 +359,18 @@ private Matcher<SearchHit>[] expectedIds(int numDocs) {
359359
.<Matcher<SearchHit>>toArray(Matcher[]::new);
360360
}
361361

362-
private static MultiGetRequest indexDocs(BulkProcessor processor, int numDocs, String localIndex, String localType,
362+
private static MultiGetRequest indexDocs(BulkProcessor processor, int numDocs, String localIndex,
363363
String globalIndex, String globalType, String globalPipeline) throws Exception {
364364
MultiGetRequest multiGetRequest = new MultiGetRequest();
365365
for (int i = 1; i <= numDocs; i++) {
366366
if (randomBoolean()) {
367-
processor.add(new IndexRequest(localIndex, localType, Integer.toString(i))
367+
processor.add(new IndexRequest(localIndex, "_doc", Integer.toString(i))
368368
.source(XContentType.JSON, "field", randomRealisticUnicodeOfLengthBetween(1, 30)));
369369
} else {
370-
BytesArray data = bytesBulkRequest(localIndex, localType, i);
370+
BytesArray data = bytesBulkRequest(localIndex, "_doc", i);
371371
processor.add(data, globalIndex, globalType, globalPipeline, null, XContentType.JSON);
372372
}
373-
multiGetRequest.add(localIndex, localType, Integer.toString(i));
373+
multiGetRequest.add(localIndex, Integer.toString(i));
374374
}
375375
return multiGetRequest;
376376
}
@@ -396,15 +396,15 @@ private static BytesArray bytesBulkRequest(String localIndex, String localType,
396396
}
397397

398398
private static MultiGetRequest indexDocs(BulkProcessor processor, int numDocs) throws Exception {
399-
return indexDocs(processor, numDocs, "test", "test", null, null, null);
399+
return indexDocs(processor, numDocs, "test", null, null, null);
400400
}
401401

402402
private static void assertResponseItems(List<BulkItemResponse> bulkItemResponses, int numDocs) {
403403
assertThat(bulkItemResponses.size(), is(numDocs));
404404
int i = 1;
405405
for (BulkItemResponse bulkItemResponse : bulkItemResponses) {
406406
assertThat(bulkItemResponse.getIndex(), equalTo("test"));
407-
assertThat(bulkItemResponse.getType(), equalTo("test"));
407+
assertThat(bulkItemResponse.getType(), equalTo("_doc"));
408408
assertThat(bulkItemResponse.getId(), equalTo(Integer.toString(i++)));
409409
assertThat("item " + i + " failed with cause: " + bulkItemResponse.getFailureMessage(),
410410
bulkItemResponse.isFailed(), equalTo(false));
@@ -416,7 +416,7 @@ private static void assertMultiGetResponse(MultiGetResponse multiGetResponse, in
416416
int i = 1;
417417
for (MultiGetItemResponse multiGetItemResponse : multiGetResponse) {
418418
assertThat(multiGetItemResponse.getIndex(), equalTo("test"));
419-
assertThat(multiGetItemResponse.getType(), equalTo("test"));
419+
assertThat(multiGetItemResponse.getType(), equalTo("_doc"));
420420
assertThat(multiGetItemResponse.getId(), equalTo(Integer.toString(i++)));
421421
}
422422
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
public class BulkProcessorRetryIT extends ESRestHighLevelClientTestCase {
4646

4747
private static final String INDEX_NAME = "index";
48-
private static final String TYPE_NAME = "type";
4948

5049
private static BulkProcessor.Builder initBulkProcessorBuilder(BulkProcessor.Listener listener) {
5150
return BulkProcessor.builder(
@@ -144,9 +143,9 @@ public void afterBulk(long executionId, BulkRequest request, Throwable failure)
144143
private static MultiGetRequest indexDocs(BulkProcessor processor, int numDocs) {
145144
MultiGetRequest multiGetRequest = new MultiGetRequest();
146145
for (int i = 1; i <= numDocs; i++) {
147-
processor.add(new IndexRequest(INDEX_NAME, TYPE_NAME, Integer.toString(i))
146+
processor.add(new IndexRequest(INDEX_NAME, "_doc", Integer.toString(i))
148147
.source(XContentType.JSON, "field", randomRealisticUnicodeOfCodepointLengthBetween(1, 30)));
149-
multiGetRequest.add(INDEX_NAME, TYPE_NAME, Integer.toString(i));
148+
multiGetRequest.add(INDEX_NAME, Integer.toString(i));
150149
}
151150
return multiGetRequest;
152151
}

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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -175,46 +175,46 @@ public void testDelete() throws IOException {
175175

176176
public void testExists() throws IOException {
177177
{
178-
GetRequest getRequest = new GetRequest("index", "_doc", "id");
178+
GetRequest getRequest = new GetRequest("index", "id");
179179
assertFalse(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
180180
}
181181
IndexRequest index = new IndexRequest("index", "_doc", "id");
182182
index.source("{\"field1\":\"value1\",\"field2\":\"value2\"}", XContentType.JSON);
183183
index.setRefreshPolicy(RefreshPolicy.IMMEDIATE);
184184
highLevelClient().index(index, RequestOptions.DEFAULT);
185185
{
186-
GetRequest getRequest = new GetRequest("index", "_doc", "id");
186+
GetRequest getRequest = new GetRequest("index", "id");
187187
assertTrue(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
188188
}
189189
{
190-
GetRequest getRequest = new GetRequest("index", "_doc", "does_not_exist");
190+
GetRequest getRequest = new GetRequest("index", "does_not_exist");
191191
assertFalse(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
192192
}
193193
{
194-
GetRequest getRequest = new GetRequest("index", "_doc", "does_not_exist").version(1);
194+
GetRequest getRequest = new GetRequest("index", "does_not_exist").version(1);
195195
assertFalse(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
196196
}
197197
}
198198

199199
public void testSourceExists() throws IOException {
200200
{
201-
GetRequest getRequest = new GetRequest("index", "_doc", "id");
201+
GetRequest getRequest = new GetRequest("index", "id");
202202
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
203203
}
204204
IndexRequest index = new IndexRequest("index", "_doc", "id");
205205
index.source("{\"field1\":\"value1\",\"field2\":\"value2\"}", XContentType.JSON);
206206
index.setRefreshPolicy(RefreshPolicy.IMMEDIATE);
207207
highLevelClient().index(index, RequestOptions.DEFAULT);
208208
{
209-
GetRequest getRequest = new GetRequest("index", "_doc", "id");
209+
GetRequest getRequest = new GetRequest("index", "id");
210210
assertTrue(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
211211
}
212212
{
213-
GetRequest getRequest = new GetRequest("index", "_doc", "does_not_exist");
213+
GetRequest getRequest = new GetRequest("index", "does_not_exist");
214214
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
215215
}
216216
{
217-
GetRequest getRequest = new GetRequest("index", "_doc", "does_not_exist").version(1);
217+
GetRequest getRequest = new GetRequest("index", "does_not_exist").version(1);
218218
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
219219
}
220220
}
@@ -245,15 +245,15 @@ public void testSourceDoesNotExist() throws IOException {
245245
);
246246
}
247247
{
248-
GetRequest getRequest = new GetRequest(noSourceIndex, "_doc", "1");
248+
GetRequest getRequest = new GetRequest(noSourceIndex, "1");
249249
assertTrue(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
250250
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
251251
}
252252
}
253253

254254
public void testGet() throws IOException {
255255
{
256-
GetRequest getRequest = new GetRequest("index", "_doc", "id");
256+
GetRequest getRequest = new GetRequest("index", "id");
257257
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
258258
() -> execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync));
259259
assertEquals(RestStatus.NOT_FOUND, exception.status());
@@ -266,7 +266,7 @@ public void testGet() throws IOException {
266266
index.setRefreshPolicy(RefreshPolicy.IMMEDIATE);
267267
highLevelClient().index(index, RequestOptions.DEFAULT);
268268
{
269-
GetRequest getRequest = new GetRequest("index", "_doc", "id").version(2);
269+
GetRequest getRequest = new GetRequest("index", "id").version(2);
270270
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
271271
() -> execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync));
272272
assertEquals(RestStatus.CONFLICT, exception.status());
@@ -275,7 +275,7 @@ public void testGet() throws IOException {
275275
assertEquals("index", exception.getMetadata("es.index").get(0));
276276
}
277277
{
278-
GetRequest getRequest = new GetRequest("index", "_doc", "id");
278+
GetRequest getRequest = new GetRequest("index", "id");
279279
if (randomBoolean()) {
280280
getRequest.version(1L);
281281
}
@@ -289,7 +289,7 @@ public void testGet() throws IOException {
289289
assertEquals(document, getResponse.getSourceAsString());
290290
}
291291
{
292-
GetRequest getRequest = new GetRequest("index", "_doc", "does_not_exist");
292+
GetRequest getRequest = new GetRequest("index", "does_not_exist");
293293
GetResponse getResponse = execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync);
294294
assertEquals("index", getResponse.getIndex());
295295
assertEquals("_doc", getResponse.getType());
@@ -300,7 +300,7 @@ public void testGet() throws IOException {
300300
assertNull(getResponse.getSourceAsString());
301301
}
302302
{
303-
GetRequest getRequest = new GetRequest("index", "_doc", "id");
303+
GetRequest getRequest = new GetRequest("index", "id");
304304
getRequest.fetchSourceContext(new FetchSourceContext(false, Strings.EMPTY_ARRAY, Strings.EMPTY_ARRAY));
305305
GetResponse getResponse = execute(getRequest, highLevelClient()::get, highLevelClient()::getAsync);
306306
assertEquals("index", getResponse.getIndex());
@@ -312,7 +312,7 @@ public void testGet() throws IOException {
312312
assertNull(getResponse.getSourceAsString());
313313
}
314314
{
315-
GetRequest getRequest = new GetRequest("index", "_doc", "id");
315+
GetRequest getRequest = new GetRequest("index", "id");
316316
if (randomBoolean()) {
317317
getRequest.fetchSourceContext(new FetchSourceContext(true, new String[]{"field1"}, Strings.EMPTY_ARRAY));
318318
} else {
@@ -334,23 +334,23 @@ public void testGet() throws IOException {
334334
public void testMultiGet() throws IOException {
335335
{
336336
MultiGetRequest multiGetRequest = new MultiGetRequest();
337-
multiGetRequest.add("index", "_doc", "id1");
338-
multiGetRequest.add("index", "_doc", "id2");
337+
multiGetRequest.add("index", "id1");
338+
multiGetRequest.add("index", "id2");
339339
MultiGetResponse response = execute(multiGetRequest, highLevelClient()::mget, highLevelClient()::mgetAsync);
340340
assertEquals(2, response.getResponses().length);
341341

342342
assertTrue(response.getResponses()[0].isFailed());
343343
assertNull(response.getResponses()[0].getResponse());
344344
assertEquals("id1", response.getResponses()[0].getFailure().getId());
345-
assertEquals("_doc", response.getResponses()[0].getFailure().getType());
345+
assertNull(response.getResponses()[0].getFailure().getType());
346346
assertEquals("index", response.getResponses()[0].getFailure().getIndex());
347347
assertEquals("Elasticsearch exception [type=index_not_found_exception, reason=no such index [index]]",
348348
response.getResponses()[0].getFailure().getFailure().getMessage());
349349

350350
assertTrue(response.getResponses()[1].isFailed());
351351
assertNull(response.getResponses()[1].getResponse());
352352
assertEquals("id2", response.getResponses()[1].getId());
353-
assertEquals("_doc", response.getResponses()[1].getType());
353+
assertNull(response.getResponses()[1].getType());
354354
assertEquals("index", response.getResponses()[1].getIndex());
355355
assertEquals("Elasticsearch exception [type=index_not_found_exception, reason=no such index [index]]",
356356
response.getResponses()[1].getFailure().getFailure().getMessage());
@@ -366,8 +366,8 @@ public void testMultiGet() throws IOException {
366366
highLevelClient().bulk(bulk, RequestOptions.DEFAULT);
367367
{
368368
MultiGetRequest multiGetRequest = new MultiGetRequest();
369-
multiGetRequest.add("index", "_doc", "id1");
370-
multiGetRequest.add("index", "_doc", "id2");
369+
multiGetRequest.add("index", "id1");
370+
multiGetRequest.add("index", "id2");
371371
MultiGetResponse response = execute(multiGetRequest, highLevelClient()::mget, highLevelClient()::mgetAsync);
372372
assertEquals(2, response.getResponses().length);
373373

@@ -789,7 +789,7 @@ public void testUpdateByQuery() throws Exception {
789789
assertEquals(0, bulkResponse.getSearchFailures().size());
790790
assertEquals(
791791
3,
792-
(int) (highLevelClient().get(new GetRequest(sourceIndex, "_doc", "2"), RequestOptions.DEFAULT)
792+
(int) (highLevelClient().get(new GetRequest(sourceIndex, "2"), RequestOptions.DEFAULT)
793793
.getSourceAsMap().get("foo"))
794794
);
795795
}
@@ -1059,7 +1059,7 @@ public void testUrlEncode() throws IOException {
10591059
assertEquals("id#1", indexResponse.getId());
10601060
}
10611061
{
1062-
GetRequest getRequest = new GetRequest(indexPattern, "_doc", "id#1");
1062+
GetRequest getRequest = new GetRequest(indexPattern, "id#1");
10631063
GetResponse getResponse = highLevelClient().get(getRequest, RequestOptions.DEFAULT);
10641064
assertTrue(getResponse.isExists());
10651065
assertEquals(expectedIndex, getResponse.getIndex());
@@ -1077,7 +1077,7 @@ public void testUrlEncode() throws IOException {
10771077
assertEquals(docId, indexResponse.getId());
10781078
}
10791079
{
1080-
GetRequest getRequest = new GetRequest("index", "_doc", docId);
1080+
GetRequest getRequest = new GetRequest("index", docId);
10811081
GetResponse getResponse = highLevelClient().get(getRequest, RequestOptions.DEFAULT);
10821082
assertTrue(getResponse.isExists());
10831083
assertEquals("index", getResponse.getIndex());
@@ -1101,7 +1101,7 @@ public void testParamsEncode() throws IOException {
11011101
assertEquals("id", indexResponse.getId());
11021102
}
11031103
{
1104-
GetRequest getRequest = new GetRequest("index", "_doc", "id").routing(routing);
1104+
GetRequest getRequest = new GetRequest("index", "id").routing(routing);
11051105
GetResponse getResponse = highLevelClient().get(getRequest, RequestOptions.DEFAULT);
11061106
assertTrue(getResponse.isExists());
11071107
assertEquals("index", getResponse.getIndex());

0 commit comments

Comments
 (0)