|
41 | 41 | import java.io.IOException; |
42 | 42 | import java.util.ArrayList; |
43 | 43 | import java.util.Collection; |
| 44 | +import java.util.HashMap; |
44 | 45 | import java.util.List; |
45 | 46 | import java.util.Locale; |
46 | 47 | import java.util.Map; |
@@ -653,13 +654,30 @@ public void testUpdateDoc() throws Exception { |
653 | 654 | .put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1) |
654 | 655 | .put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 2); |
655 | 656 | createIndex(index, settings.build()); |
| 657 | + indexDocs(index, 0, 100); |
656 | 658 | } |
657 | | - ensureGreen(index); |
658 | | - indexDocs(index, 0, 10); |
659 | | - for (int i = 0; i < 10; i++) { |
660 | | - Request update = new Request("POST", index + "/_update/" + i); |
661 | | - update.setJsonEntity("{\"doc\": {\"f\": " + randomNonNegativeLong() + "}}"); |
662 | | - client().performRequest(update); |
| 659 | + if (randomBoolean()) { |
| 660 | + ensureGreen(index); |
| 661 | + } |
| 662 | + Map<Integer, Long> updates = new HashMap<>(); |
| 663 | + for (int docId = 0; docId < 100; docId++) { |
| 664 | + final int times = randomIntBetween(0, 2); |
| 665 | + for (int i = 0; i < times; i++) { |
| 666 | + long value = randomNonNegativeLong(); |
| 667 | + Request update = new Request("POST", index + "/_update/" + docId); |
| 668 | + update.setJsonEntity("{\"doc\": {\"updated_field\": " + value + "}}"); |
| 669 | + client().performRequest(update); |
| 670 | + updates.put(docId, value); |
| 671 | + } |
| 672 | + } |
| 673 | + client().performRequest(new Request("POST", index + "/_refresh")); |
| 674 | + for (int docId : updates.keySet()) { |
| 675 | + Request get = new Request("GET", index + "/_doc/" + docId); |
| 676 | + Map<String, Object> doc = entityAsMap(client().performRequest(get)); |
| 677 | + assertThat(XContentMapValues.extractValue("_source.updated_field", doc), equalTo(updates.get(docId))); |
| 678 | + } |
| 679 | + if (randomBoolean()) { |
| 680 | + syncedFlush(index); |
663 | 681 | } |
664 | 682 | } |
665 | 683 |
|
|
0 commit comments