Skip to content

Commit

Permalink
Deprecate types in index API
Browse files Browse the repository at this point in the history
- deprecate type-based constructors of IndexRequest
- update tests to use typeless IndexRequest constructors
- no yaml tests as they have been already added in elastic#35790

Relates to elastic#35190
  • Loading branch information
mayya-sharipova committed Dec 16, 2018
1 parent 97107e9 commit 560315b
Show file tree
Hide file tree
Showing 40 changed files with 403 additions and 296 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,12 @@ public void testBulkProcessorConcurrentRequestsReadOnlyIndex() throws Exception
for (int i = 1; i <= numDocs; i++) {
if (randomBoolean()) {
testDocs++;
processor.add(new IndexRequest("test", "_doc", Integer.toString(testDocs))
processor.add(new IndexRequest("test").id(Integer.toString(testDocs))
.source(XContentType.JSON, "field", "value"));
multiGetRequest.add("test", Integer.toString(testDocs));
} else {
testReadOnlyDocs++;
processor.add(new IndexRequest("test-ro", "_doc", Integer.toString(testReadOnlyDocs))
processor.add(new IndexRequest("test-ro").id(Integer.toString(testReadOnlyDocs))
.source(XContentType.JSON, "field", "value"));
}
}
Expand Down Expand Up @@ -300,7 +300,7 @@ public void testGlobalParametersAndSingleRequest() throws Exception {

processor.add(new IndexRequest() // <1>
.source(XContentType.JSON, "user", "some user"));
processor.add(new IndexRequest("blogs", "post_type", "1") // <2>
processor.add(new IndexRequest("blogs").id("1") // <2>
.source(XContentType.JSON, "title", "some title"));
}
// end::bulk-processor-mix-parameters
Expand Down Expand Up @@ -364,7 +364,7 @@ private static MultiGetRequest indexDocs(BulkProcessor processor, int numDocs, S
MultiGetRequest multiGetRequest = new MultiGetRequest();
for (int i = 1; i <= numDocs; i++) {
if (randomBoolean()) {
processor.add(new IndexRequest(localIndex, "_doc", Integer.toString(i))
processor.add(new IndexRequest(localIndex).id(Integer.toString(i))
.source(XContentType.JSON, "field", randomRealisticUnicodeOfLengthBetween(1, 30)));
} else {
BytesArray data = bytesBulkRequest(localIndex, "_doc", i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public void testGlobalPipelineOnBulkRequest() throws IOException {
createFieldAddingPipleine("xyz", "fieldNameXYZ", "valueXYZ");

BulkRequest request = new BulkRequest();
request.add(new IndexRequest("test", "doc", "1")
request.add(new IndexRequest("test").id("1")
.source(XContentType.JSON, "field", "bulk1"));
request.add(new IndexRequest("test", "doc", "2")
request.add(new IndexRequest("test").id("2")
.source(XContentType.JSON, "field", "bulk2"));
request.pipeline("xyz");

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

BulkRequest request = new BulkRequest();
request.pipeline("globalId");
request.add(new IndexRequest("test", "doc", "1")
request.add(new IndexRequest("test").id("1")
.source(XContentType.JSON, "field", "bulk1")
.setPipeline("perIndexId"));
request.add(new IndexRequest("test", "doc", "2")
request.add(new IndexRequest("test").id("2")
.source(XContentType.JSON, "field", "bulk2")
.setPipeline("perIndexId"));

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

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

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

public void testGlobalIndex() throws IOException {
BulkRequest request = new BulkRequest("global_index", null);
request.add(new IndexRequest().type("doc").id("1")
request.add(new IndexRequest().id("1")
.source(XContentType.JSON, "field", "bulk1"));
request.add(new IndexRequest().type("doc").id("2")
request.add(new IndexRequest().id("2")
.source(XContentType.JSON, "field", "bulk2"));

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

bulk(request);
Expand All @@ -140,7 +140,7 @@ public void testIndexGlobalAndPerRequest() throws IOException {
}

public void testGlobalType() throws IOException {
BulkRequest request = new BulkRequest(null, "global_type");
BulkRequest request = new BulkRequest(null, "_doc");
request.add(new IndexRequest("index").id("1")
.source(XContentType.JSON, "field", "bulk1"));
request.add(new IndexRequest("index").id("2")
Expand All @@ -149,34 +149,16 @@ public void testGlobalType() throws IOException {
bulk(request);

Iterable<SearchHit> hits = searchAll("index");
assertThat(hits, everyItem(hasType("global_type")));
}

@SuppressWarnings("unchecked")
public void testTypeGlobalAndPerRequest() throws IOException {
BulkRequest request = new BulkRequest(null, "global_type");
request.add(new IndexRequest("index1", "local_type", "1")
.source(XContentType.JSON, "field", "bulk1"));
request.add(new IndexRequest("index2").id("2") // will take global type
.source(XContentType.JSON, "field", "bulk2"));

bulk(request);

Iterable<SearchHit> hits = searchAll("index1", "index2");
assertThat(hits, containsInAnyOrder(
both(hasId("1"))
.and(hasType("local_type")),
both(hasId("2"))
.and(hasType("global_type"))));
assertThat(hits, everyItem(hasType("_doc")));
}

@SuppressWarnings("unchecked")
public void testGlobalRouting() throws IOException {
createIndexWithMultipleShards("index");
BulkRequest request = new BulkRequest(null, null);
request.add(new IndexRequest("index", "type", "1")
request.add(new IndexRequest("index").id("1")
.source(XContentType.JSON, "field", "bulk1"));
request.add(new IndexRequest("index", "type", "2")
request.add(new IndexRequest("index").id("2")
.source(XContentType.JSON, "field", "bulk1"));
request.routing("1");
bulk(request);
Expand All @@ -192,9 +174,9 @@ public void testGlobalRouting() throws IOException {
public void testMixLocalAndGlobalRouting() throws IOException {
BulkRequest request = new BulkRequest(null, null);
request.routing("globalRouting");
request.add(new IndexRequest("index", "type", "1")
request.add(new IndexRequest("index").id("1")
.source(XContentType.JSON, "field", "bulk1"));
request.add(new IndexRequest("index", "type", "2")
request.add(new IndexRequest("index").id( "2")
.routing("localRouting")
.source(XContentType.JSON, "field", "bulk1"));

Expand Down
Loading

0 comments on commit 560315b

Please sign in to comment.