Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate types in index API #36575

Merged
merged 7 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to leave this in (with expectWarnings calls), as I don't see this functionality being tested elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtibshirani Thanks for the suggestion, Julie. But this test will not work anymore, as creating an IndexRequest without a type like new IndexRequest("index2").id("2") will assign a type of _doc to it. While the test here checks that that that the result type should be "global_type".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to temporary disable this test with AwaitsFix, and let @markharwood address this test through his bulk API change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't realize this was actually broken. I now see it is also broken for update and delete. I would also be okay adding AwaitsFix, and we can work to fix the issue as soon as possible in another PR.

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