Skip to content

Commit f884b2b

Browse files
Deprecate types in index API (#36575)
* Deprecate types in index API - deprecate type-based constructors of IndexRequest - update tests to use typeless IndexRequest constructors - no yaml tests as they have been already added in #35790 Relates to #35190
1 parent 1a46d15 commit f884b2b

File tree

43 files changed

+420
-295
lines changed

Some content is hidden

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

43 files changed

+420
-295
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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", "_doc", Integer.toString(testDocs))
243+
processor.add(new IndexRequest("test").id(Integer.toString(testDocs))
244244
.source(XContentType.JSON, "field", "value"));
245245
multiGetRequest.add("test", Integer.toString(testDocs));
246246
} else {
247247
testReadOnlyDocs++;
248-
processor.add(new IndexRequest("test-ro", "_doc", Integer.toString(testReadOnlyDocs))
248+
processor.add(new IndexRequest("test-ro").id(Integer.toString(testReadOnlyDocs))
249249
.source(XContentType.JSON, "field", "value"));
250250
}
251251
}
@@ -300,7 +300,7 @@ public void testGlobalParametersAndSingleRequest() throws Exception {
300300

301301
processor.add(new IndexRequest() // <1>
302302
.source(XContentType.JSON, "user", "some user"));
303-
processor.add(new IndexRequest("blogs", "post_type", "1") // <2>
303+
processor.add(new IndexRequest("blogs").id("1") // <2>
304304
.source(XContentType.JSON, "title", "some title"));
305305
}
306306
// end::bulk-processor-mix-parameters
@@ -364,7 +364,7 @@ private static MultiGetRequest indexDocs(BulkProcessor processor, int numDocs, S
364364
MultiGetRequest multiGetRequest = new MultiGetRequest();
365365
for (int i = 1; i <= numDocs; i++) {
366366
if (randomBoolean()) {
367-
processor.add(new IndexRequest(localIndex, "_doc", Integer.toString(i))
367+
processor.add(new IndexRequest(localIndex).id(Integer.toString(i))
368368
.source(XContentType.JSON, "field", randomRealisticUnicodeOfLengthBetween(1, 30)));
369369
} else {
370370
BytesArray data = bytesBulkRequest(localIndex, "_doc", i);

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public void testGlobalPipelineOnBulkRequest() throws IOException {
4848
createFieldAddingPipleine("xyz", "fieldNameXYZ", "valueXYZ");
4949

5050
BulkRequest request = new BulkRequest();
51-
request.add(new IndexRequest("test", "doc", "1")
51+
request.add(new IndexRequest("test").id("1")
5252
.source(XContentType.JSON, "field", "bulk1"));
53-
request.add(new IndexRequest("test", "doc", "2")
53+
request.add(new IndexRequest("test").id("2")
5454
.source(XContentType.JSON, "field", "bulk2"));
5555
request.pipeline("xyz");
5656

@@ -67,10 +67,10 @@ public void testPipelineOnRequestOverridesGlobalPipeline() throws IOException {
6767

6868
BulkRequest request = new BulkRequest();
6969
request.pipeline("globalId");
70-
request.add(new IndexRequest("test", "doc", "1")
70+
request.add(new IndexRequest("test").id("1")
7171
.source(XContentType.JSON, "field", "bulk1")
7272
.setPipeline("perIndexId"));
73-
request.add(new IndexRequest("test", "doc", "2")
73+
request.add(new IndexRequest("test").id("2")
7474
.source(XContentType.JSON, "field", "bulk2")
7575
.setPipeline("perIndexId"));
7676

@@ -91,11 +91,11 @@ public void testMixPipelineOnRequestAndGlobal() throws IOException {
9191
BulkRequest request = new BulkRequest();
9292
request.pipeline("globalId");
9393

94-
request.add(new IndexRequest("test", "doc", "1")
94+
request.add(new IndexRequest("test").id("1")
9595
.source(XContentType.JSON, "field", "bulk1")
9696
.setPipeline("perIndexId")); // <1>
9797

98-
request.add(new IndexRequest("test", "doc", "2")
98+
request.add(new IndexRequest("test").id("2")
9999
.source(XContentType.JSON, "field", "bulk2")); // <2>
100100
// end::bulk-request-mix-pipeline
101101
bulk(request);
@@ -110,9 +110,9 @@ public void testMixPipelineOnRequestAndGlobal() throws IOException {
110110

111111
public void testGlobalIndex() throws IOException {
112112
BulkRequest request = new BulkRequest("global_index", null);
113-
request.add(new IndexRequest().type("doc").id("1")
113+
request.add(new IndexRequest().id("1")
114114
.source(XContentType.JSON, "field", "bulk1"));
115-
request.add(new IndexRequest().type("doc").id("2")
115+
request.add(new IndexRequest().id("2")
116116
.source(XContentType.JSON, "field", "bulk2"));
117117

118118
bulk(request);
@@ -124,9 +124,9 @@ public void testGlobalIndex() throws IOException {
124124
@SuppressWarnings("unchecked")
125125
public void testIndexGlobalAndPerRequest() throws IOException {
126126
BulkRequest request = new BulkRequest("global_index", null);
127-
request.add(new IndexRequest("local_index", "doc", "1")
127+
request.add(new IndexRequest("local_index").id("1")
128128
.source(XContentType.JSON, "field", "bulk1"));
129-
request.add(new IndexRequest().type("doc").id("2") // will take global index
129+
request.add(new IndexRequest().id("2") // will take global index
130130
.source(XContentType.JSON, "field", "bulk2"));
131131

132132
bulk(request);
@@ -140,7 +140,7 @@ public void testIndexGlobalAndPerRequest() throws IOException {
140140
}
141141

142142
public void testGlobalType() throws IOException {
143-
BulkRequest request = new BulkRequest(null, "global_type");
143+
BulkRequest request = new BulkRequest(null, "_doc");
144144
request.add(new IndexRequest("index").id("1")
145145
.source(XContentType.JSON, "field", "bulk1"));
146146
request.add(new IndexRequest("index").id("2")
@@ -149,10 +149,11 @@ public void testGlobalType() throws IOException {
149149
bulk(request);
150150

151151
Iterable<SearchHit> hits = searchAll("index");
152-
assertThat(hits, everyItem(hasType("global_type")));
152+
assertThat(hits, everyItem(hasType("_doc")));
153153
}
154154

155155
@SuppressWarnings("unchecked")
156+
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/pull/36549")
156157
public void testTypeGlobalAndPerRequest() throws IOException {
157158
BulkRequest request = new BulkRequest(null, "global_type");
158159
request.add(new IndexRequest("index1", "local_type", "1")
@@ -174,9 +175,9 @@ public void testTypeGlobalAndPerRequest() throws IOException {
174175
public void testGlobalRouting() throws IOException {
175176
createIndexWithMultipleShards("index");
176177
BulkRequest request = new BulkRequest(null, null);
177-
request.add(new IndexRequest("index", "type", "1")
178+
request.add(new IndexRequest("index").id("1")
178179
.source(XContentType.JSON, "field", "bulk1"));
179-
request.add(new IndexRequest("index", "type", "2")
180+
request.add(new IndexRequest("index").id("2")
180181
.source(XContentType.JSON, "field", "bulk1"));
181182
request.routing("1");
182183
bulk(request);
@@ -192,9 +193,9 @@ public void testGlobalRouting() throws IOException {
192193
public void testMixLocalAndGlobalRouting() throws IOException {
193194
BulkRequest request = new BulkRequest(null, null);
194195
request.routing("globalRouting");
195-
request.add(new IndexRequest("index", "type", "1")
196+
request.add(new IndexRequest("index").id("1")
196197
.source(XContentType.JSON, "field", "bulk1"));
197-
request.add(new IndexRequest("index", "type", "2")
198+
request.add(new IndexRequest("index").id( "2")
198199
.routing("localRouting")
199200
.source(XContentType.JSON, "field", "bulk1"));
200201

0 commit comments

Comments
 (0)