|
34 | 34 | import org.elasticsearch.index.IndexSettings;
|
35 | 35 | import org.elasticsearch.index.seqno.RetentionLeaseUtils;
|
36 | 36 | import org.elasticsearch.rest.RestStatus;
|
| 37 | +import org.elasticsearch.rest.action.document.RestGetAction; |
37 | 38 | import org.elasticsearch.rest.action.document.RestIndexAction;
|
38 | 39 | import org.elasticsearch.rest.action.document.RestUpdateAction;
|
39 | 40 | import org.elasticsearch.test.rest.yaml.ObjectPath;
|
|
43 | 44 | import java.io.IOException;
|
44 | 45 | import java.util.ArrayList;
|
45 | 46 | import java.util.Collection;
|
| 47 | +import java.util.HashMap; |
46 | 48 | import java.util.List;
|
47 | 49 | import java.util.Locale;
|
48 | 50 | import java.util.Map;
|
@@ -694,14 +696,32 @@ public void testUpdateDoc() throws Exception {
|
694 | 696 | .put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1)
|
695 | 697 | .put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 2);
|
696 | 698 | createIndex(index, settings.build());
|
| 699 | + indexDocs(index, 0, 100); |
697 | 700 | }
|
698 |
| - ensureGreen(index); |
699 |
| - indexDocs(index, 0, 10); |
700 |
| - for (int i = 0; i < 10; i++) { |
701 |
| - Request update = new Request("POST", index + "/test/" + i + "/_update/"); |
702 |
| - update.setOptions(expectWarnings(RestUpdateAction.TYPES_DEPRECATION_MESSAGE)); |
703 |
| - update.setJsonEntity("{\"doc\": {\"f\": " + randomNonNegativeLong() + "}}"); |
704 |
| - client().performRequest(update); |
| 701 | + if (randomBoolean()) { |
| 702 | + ensureGreen(index); |
| 703 | + } |
| 704 | + Map<Integer, Long> updates = new HashMap<>(); |
| 705 | + for (int docId = 0; docId < 100; docId++) { |
| 706 | + final int times = randomIntBetween(0, 2); |
| 707 | + for (int i = 0; i < times; i++) { |
| 708 | + long value = randomNonNegativeLong(); |
| 709 | + Request update = new Request("POST", index + "/test/" + docId + "/_update"); |
| 710 | + update.setOptions(expectWarnings(RestUpdateAction.TYPES_DEPRECATION_MESSAGE)); |
| 711 | + update.setJsonEntity("{\"doc\": {\"updated_field\": " + value + "}}"); |
| 712 | + client().performRequest(update); |
| 713 | + updates.put(docId, value); |
| 714 | + } |
| 715 | + } |
| 716 | + client().performRequest(new Request("POST", index + "/_refresh")); |
| 717 | + for (int docId : updates.keySet()) { |
| 718 | + Request get = new Request("GET", index + "/test/" + docId); |
| 719 | + get.setOptions(expectWarnings(RestGetAction.TYPES_DEPRECATION_MESSAGE)); |
| 720 | + Map<String, Object> doc = entityAsMap(client().performRequest(get)); |
| 721 | + assertThat(XContentMapValues.extractValue("_source.updated_field", doc), equalTo(updates.get(docId))); |
| 722 | + } |
| 723 | + if (randomBoolean()) { |
| 724 | + syncedFlush(index); |
705 | 725 | }
|
706 | 726 | }
|
707 | 727 |
|
|
0 commit comments