|
25 | 25 | import org.elasticsearch.action.delete.DeleteRequest; |
26 | 26 | import org.elasticsearch.action.get.GetResponse; |
27 | 27 | import org.elasticsearch.action.index.IndexRequest; |
| 28 | +import org.elasticsearch.action.index.IndexResponse; |
28 | 29 | import org.elasticsearch.action.search.SearchResponse; |
29 | 30 | import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; |
30 | 31 | import org.elasticsearch.action.update.UpdateRequest; |
31 | 32 | import org.elasticsearch.action.update.UpdateRequestBuilder; |
32 | 33 | import org.elasticsearch.action.update.UpdateResponse; |
33 | 34 | import org.elasticsearch.client.Requests; |
34 | 35 | import org.elasticsearch.cluster.metadata.IndexMetaData; |
| 36 | +import org.elasticsearch.common.Strings; |
35 | 37 | import org.elasticsearch.common.settings.Settings; |
36 | 38 | import org.elasticsearch.common.xcontent.XContentType; |
37 | 39 | import org.elasticsearch.index.VersionType; |
|
57 | 59 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
58 | 60 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; |
59 | 61 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; |
| 62 | +import static org.hamcrest.Matchers.arrayWithSize; |
60 | 63 | import static org.hamcrest.Matchers.containsString; |
61 | 64 | import static org.hamcrest.Matchers.equalTo; |
62 | 65 | import static org.hamcrest.Matchers.instanceOf; |
@@ -618,5 +621,31 @@ public void testInvalidIndexNamesCorrectOpType() { |
618 | 621 | assertThat(bulkResponse.getItems()[1].getOpType(), is(OpType.UPDATE)); |
619 | 622 | assertThat(bulkResponse.getItems()[2].getOpType(), is(OpType.DELETE)); |
620 | 623 | } |
| 624 | + |
| 625 | + public void testNoopUpdate() { |
| 626 | + String indexName = "test"; |
| 627 | + createIndex(indexName, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).build()); |
| 628 | + internalCluster().ensureAtLeastNumDataNodes(2); |
| 629 | + ensureGreen(indexName); |
| 630 | + IndexResponse doc = index(indexName, "_doc", "1", Map.of("user", "xyz")); |
| 631 | + assertThat(doc.getShardInfo().getSuccessful(), equalTo(2)); |
| 632 | + final BulkResponse bulkResponse = client().prepareBulk() |
| 633 | + .add(new UpdateRequest().index(indexName).id("1").detectNoop(true).doc("user", "xyz")) // noop update |
| 634 | + .add(new UpdateRequest().index(indexName).id("2").docAsUpsert(false).doc("f", "v")) // not_found update |
| 635 | + .add(new DeleteRequest().index(indexName).id("2")) // not_found delete |
| 636 | + .get(); |
| 637 | + assertThat(bulkResponse.getItems(), arrayWithSize(3)); |
| 638 | + |
| 639 | + final BulkItemResponse noopUpdate = bulkResponse.getItems()[0]; |
| 640 | + assertThat(noopUpdate.getResponse().getResult(), equalTo(DocWriteResponse.Result.NOOP)); |
| 641 | + assertThat(Strings.toString(noopUpdate), noopUpdate.getResponse().getShardInfo().getSuccessful(), equalTo(2)); |
| 642 | + |
| 643 | + final BulkItemResponse notFoundUpdate = bulkResponse.getItems()[1]; |
| 644 | + assertNotNull(notFoundUpdate.getFailure()); |
| 645 | + |
| 646 | + final BulkItemResponse notFoundDelete = bulkResponse.getItems()[2]; |
| 647 | + assertThat(notFoundDelete.getResponse().getResult(), equalTo(DocWriteResponse.Result.NOT_FOUND)); |
| 648 | + assertThat(Strings.toString(notFoundDelete), notFoundDelete.getResponse().getShardInfo().getSuccessful(), equalTo(2)); |
| 649 | + } |
621 | 650 | } |
622 | 651 |
|
0 commit comments