Skip to content

Commit 574ec4f

Browse files
romseygeekjakelandis
authored andcommitted
IndexAction to return DocWriteResponse (elastic#99964)
IndexRequests can sometimes return an UpdateResponse rather than an IndexResponse if there is an ingest pipeline that drops documents. This commit changes IndexAction to return their common superclass DocWriteResponse.
1 parent a7c1a58 commit 574ec4f

File tree

111 files changed

+338
-364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+338
-364
lines changed

modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamIT.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.ExceptionsHelper;
1414
import org.elasticsearch.action.ActionRequestBuilder;
1515
import org.elasticsearch.action.DocWriteRequest;
16+
import org.elasticsearch.action.DocWriteResponse;
1617
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
1718
import org.elasticsearch.action.admin.indices.alias.Alias;
1819
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
@@ -48,7 +49,6 @@
4849
import org.elasticsearch.action.datastreams.ModifyDataStreamsAction;
4950
import org.elasticsearch.action.delete.DeleteRequest;
5051
import org.elasticsearch.action.index.IndexRequest;
51-
import org.elasticsearch.action.index.IndexResponse;
5252
import org.elasticsearch.action.search.MultiSearchRequestBuilder;
5353
import org.elasticsearch.action.search.MultiSearchResponse;
5454
import org.elasticsearch.action.search.SearchRequest;
@@ -297,7 +297,7 @@ public void testOtherWriteOps() throws Exception {
297297
{
298298
IndexRequest indexRequest = new IndexRequest(dataStreamName).source("{\"@timestamp\": \"2020-12-12\"}", XContentType.JSON)
299299
.opType(DocWriteRequest.OpType.CREATE);
300-
IndexResponse indexResponse = client().index(indexRequest).actionGet();
300+
DocWriteResponse indexResponse = client().index(indexRequest).actionGet();
301301
assertThat(indexResponse.getIndex(), backingIndexEqualTo(dataStreamName, 1));
302302
}
303303
{
@@ -1176,7 +1176,7 @@ public void testIndexDocsWithCustomRoutingTargetingDataStreamIsNotAllowed() thro
11761176
String dataStream = "logs-foobar";
11771177
IndexRequest indexRequest = new IndexRequest(dataStream).source("{\"@timestamp\": \"2020-12-12\"}", XContentType.JSON)
11781178
.opType(DocWriteRequest.OpType.CREATE);
1179-
IndexResponse indexResponse = client().index(indexRequest).actionGet();
1179+
DocWriteResponse indexResponse = client().index(indexRequest).actionGet();
11801180
assertThat(indexResponse.getIndex(), backingIndexEqualTo(dataStream, 1));
11811181

11821182
// Index doc with custom routing that targets the data stream
@@ -1238,7 +1238,7 @@ public void testIndexDocsWithCustomRoutingAllowed() throws Exception {
12381238
IndexRequest indexRequest = new IndexRequest(dataStream).source("{\"@timestamp\": \"2020-12-12\"}", XContentType.JSON)
12391239
.opType(DocWriteRequest.OpType.CREATE)
12401240
.routing("custom");
1241-
IndexResponse indexResponse = client().index(indexRequest).actionGet();
1241+
DocWriteResponse indexResponse = client().index(indexRequest).actionGet();
12421242
assertThat(indexResponse.getIndex(), backingIndexEqualTo(dataStream, 1));
12431243
// Index doc with custom routing that targets the data stream
12441244
IndexRequest indexRequestWithRouting = new IndexRequest(dataStream).source("@timestamp", System.currentTimeMillis())
@@ -1266,7 +1266,7 @@ public void testIndexDocsWithCustomRoutingTargetingBackingIndex() throws Excepti
12661266
// Index doc that triggers creation of a data stream
12671267
IndexRequest indexRequest = new IndexRequest("logs-foobar").source("{\"@timestamp\": \"2020-12-12\"}", XContentType.JSON)
12681268
.opType(DocWriteRequest.OpType.CREATE);
1269-
IndexResponse indexResponse = client().index(indexRequest).actionGet();
1269+
DocWriteResponse indexResponse = client().index(indexRequest).actionGet();
12701270
assertThat(indexResponse.getIndex(), backingIndexEqualTo("logs-foobar", 1));
12711271
String backingIndex = indexResponse.getIndex();
12721272

@@ -1277,7 +1277,7 @@ public void testIndexDocsWithCustomRoutingTargetingBackingIndex() throws Excepti
12771277
.id(indexResponse.getId())
12781278
.setIfPrimaryTerm(indexResponse.getPrimaryTerm())
12791279
.setIfSeqNo(indexResponse.getSeqNo());
1280-
IndexResponse response = client().index(indexRequestWithRouting).actionGet();
1280+
DocWriteResponse response = client().index(indexRequestWithRouting).actionGet();
12811281
assertThat(response.getIndex(), equalTo(backingIndex));
12821282
}
12831283

modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.elasticsearch.action.datastreams.CreateDataStreamAction;
2929
import org.elasticsearch.action.datastreams.DeleteDataStreamAction;
3030
import org.elasticsearch.action.datastreams.GetDataStreamAction;
31-
import org.elasticsearch.action.index.IndexResponse;
3231
import org.elasticsearch.action.support.IndicesOptions;
3332
import org.elasticsearch.action.support.master.AcknowledgedResponse;
3433
import org.elasticsearch.client.internal.Client;
@@ -116,7 +115,10 @@ public void setup() throws Exception {
116115
ds2BackingIndexName = dsBackingIndexName.replace("-ds-", "-ds2-");
117116
otherDs2BackingIndexName = otherDsBackingIndexName.replace("-other-ds-", "-other-ds2-");
118117

119-
IndexResponse indexResponse = client.prepareIndex("ds").setOpType(DocWriteRequest.OpType.CREATE).setSource(DOCUMENT_SOURCE).get();
118+
DocWriteResponse indexResponse = client.prepareIndex("ds")
119+
.setOpType(DocWriteRequest.OpType.CREATE)
120+
.setSource(DOCUMENT_SOURCE)
121+
.get();
120122
assertEquals(DocWriteResponse.Result.CREATED, indexResponse.getResult());
121123
id = indexResponse.getId();
122124

@@ -297,7 +299,7 @@ public void testSnapshotAndRestoreInPlace() {
297299
}
298300

299301
public void testSnapshotAndRestoreAllIncludeSpecificDataStream() throws Exception {
300-
IndexResponse indexResponse = client.prepareIndex("other-ds")
302+
DocWriteResponse indexResponse = client.prepareIndex("other-ds")
301303
.setOpType(DocWriteRequest.OpType.CREATE)
302304
.setSource(DOCUMENT_SOURCE)
303305
.get();

modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/SystemDataStreamSnapshotIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
package org.elasticsearch.datastreams;
99

1010
import org.elasticsearch.action.DocWriteRequest;
11+
import org.elasticsearch.action.DocWriteResponse;
1112
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
1213
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
1314
import org.elasticsearch.action.datastreams.CreateDataStreamAction;
1415
import org.elasticsearch.action.datastreams.DeleteDataStreamAction;
1516
import org.elasticsearch.action.datastreams.GetDataStreamAction;
16-
import org.elasticsearch.action.index.IndexResponse;
1717
import org.elasticsearch.action.support.master.AcknowledgedResponse;
1818
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
1919
import org.elasticsearch.index.IndexNotFoundException;
@@ -64,7 +64,7 @@ public void testSystemDataStreamInGlobalState() throws Exception {
6464
}
6565

6666
// Index a doc so that a concrete backing index will be created
67-
IndexResponse indexRepsonse = client().prepareIndex(SYSTEM_DATA_STREAM_NAME)
67+
DocWriteResponse indexRepsonse = client().prepareIndex(SYSTEM_DATA_STREAM_NAME)
6868
.setId("42")
6969
.setSource("{ \"@timestamp\": \"2099-03-08T11:06:07.000Z\", \"name\": \"my-name\" }", XContentType.JSON)
7070
.setOpType(DocWriteRequest.OpType.CREATE)
@@ -162,7 +162,7 @@ public void testSystemDataStreamInFeatureState() throws Exception {
162162
}
163163

164164
// Index a doc so that a concrete backing index will be created
165-
IndexResponse indexToDataStreamResponse = client().prepareIndex(SYSTEM_DATA_STREAM_NAME)
165+
DocWriteResponse indexToDataStreamResponse = client().prepareIndex(SYSTEM_DATA_STREAM_NAME)
166166
.setId("42")
167167
.setSource("{ \"@timestamp\": \"2099-03-08T11:06:07.000Z\", \"name\": \"my-name\" }", XContentType.JSON)
168168
.setOpType(DocWriteRequest.OpType.CREATE)
@@ -171,7 +171,7 @@ public void testSystemDataStreamInFeatureState() throws Exception {
171171
assertThat(indexToDataStreamResponse.status().getStatus(), oneOf(200, 201));
172172

173173
// Index a doc so that a concrete backing index will be created
174-
IndexResponse indexResponse = client().prepareIndex("my-index")
174+
DocWriteResponse indexResponse = client().prepareIndex("my-index")
175175
.setId("42")
176176
.setSource("{ \"name\": \"my-name\" }", XContentType.JSON)
177177
.setOpType(DocWriteRequest.OpType.CREATE)

modules/data-streams/src/test/java/org/elasticsearch/datastreams/TimestampFieldMapperServiceTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
package org.elasticsearch.datastreams;
1010

1111
import org.elasticsearch.action.DocWriteRequest;
12+
import org.elasticsearch.action.DocWriteResponse;
1213
import org.elasticsearch.action.admin.indices.template.put.PutComposableIndexTemplateAction;
1314
import org.elasticsearch.action.index.IndexRequest;
14-
import org.elasticsearch.action.index.IndexResponse;
1515
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
1616
import org.elasticsearch.cluster.metadata.Template;
1717
import org.elasticsearch.common.compress.CompressedXContent;
@@ -58,7 +58,7 @@ protected Collection<Class<? extends Plugin>> getPlugins() {
5858

5959
public void testGetTimestampFieldTypeForTsdbDataStream() throws IOException {
6060
createTemplate(true);
61-
IndexResponse indexResponse = indexDoc();
61+
DocWriteResponse indexResponse = indexDoc();
6262

6363
var indicesService = getInstanceFromNode(IndicesService.class);
6464
var result = indicesService.getTimestampFieldType(indexResponse.getShardId().getIndex());
@@ -67,14 +67,14 @@ public void testGetTimestampFieldTypeForTsdbDataStream() throws IOException {
6767

6868
public void testGetTimestampFieldTypeForDataStream() throws IOException {
6969
createTemplate(false);
70-
IndexResponse indexResponse = indexDoc();
70+
DocWriteResponse indexResponse = indexDoc();
7171

7272
var indicesService = getInstanceFromNode(IndicesService.class);
7373
var result = indicesService.getTimestampFieldType(indexResponse.getShardId().getIndex());
7474
assertThat(result, nullValue());
7575
}
7676

77-
private IndexResponse indexDoc() {
77+
private DocWriteResponse indexDoc() {
7878
Instant time = Instant.now();
7979
var indexRequest = new IndexRequest("k8s").opType(DocWriteRequest.OpType.CREATE);
8080
indexRequest.source(DOC.replace("$time", formatInstant(time)), XContentType.JSON);

modules/ingest-common/src/internalClusterTest/java/org/elasticsearch/ingest/common/IngestRestartIT.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import org.elasticsearch.action.DocWriteResponse;
1111
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
12-
import org.elasticsearch.action.index.IndexResponse;
1312
import org.elasticsearch.action.support.PlainActionFuture;
1413
import org.elasticsearch.action.support.WriteRequest;
1514
import org.elasticsearch.cluster.block.ClusterBlockException;
@@ -321,7 +320,7 @@ public boolean validateClusterForming() {
321320
);
322321

323322
// but this one should pass since it has a longer timeout
324-
final PlainActionFuture<IndexResponse> future = new PlainActionFuture<>();
323+
final PlainActionFuture<DocWriteResponse> future = new PlainActionFuture<>();
325324
client().prepareIndex("index")
326325
.setId("passes1")
327326
.setSource("x", 2)
@@ -333,7 +332,7 @@ public boolean validateClusterForming() {
333332
internalCluster().startNode(Settings.builder().put(GatewayService.RECOVER_AFTER_DATA_NODES_SETTING.getKey(), "1"));
334333
ensureYellow("index");
335334

336-
final IndexResponse indexResponse = future.actionGet(timeout);
335+
final DocWriteResponse indexResponse = future.actionGet(timeout);
337336
assertThat(indexResponse.status(), equalTo(RestStatus.CREATED));
338337
assertThat(indexResponse.getResult(), equalTo(DocWriteResponse.Result.CREATED));
339338

modules/ingest-geoip/src/internalClusterTest/java/org/elasticsearch/ingest/geoip/GeoIpProcessorNonIngestNodeIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
package org.elasticsearch.ingest.geoip;
1010

1111
import org.apache.lucene.util.Constants;
12+
import org.elasticsearch.action.DocWriteResponse;
1213
import org.elasticsearch.action.index.IndexRequest;
13-
import org.elasticsearch.action.index.IndexResponse;
1414
import org.elasticsearch.action.ingest.PutPipelineRequest;
1515
import org.elasticsearch.common.bytes.BytesReference;
1616
import org.elasticsearch.common.settings.Settings;
@@ -101,7 +101,7 @@ public void testLazyLoading() throws IOException {
101101
final IndexRequest indexRequest = new IndexRequest("index");
102102
indexRequest.setPipeline("geoip");
103103
indexRequest.source(Collections.singletonMap("ip", "1.1.1.1"));
104-
final IndexResponse indexResponse = client(ingestNode).index(indexRequest).actionGet();
104+
final DocWriteResponse indexResponse = client(ingestNode).index(indexRequest).actionGet();
105105
assertThat(indexResponse.status(), equalTo(RestStatus.CREATED));
106106
// now the geo-IP database should be loaded on the ingest node
107107
assertDatabaseLoadStatus(ingestNode, true);

modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/GeoIpDownloaderTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.elasticsearch.action.ActionResponse;
1515
import org.elasticsearch.action.ActionType;
1616
import org.elasticsearch.action.DocWriteRequest.OpType;
17+
import org.elasticsearch.action.DocWriteResponse;
1718
import org.elasticsearch.action.admin.indices.flush.FlushAction;
1819
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
1920
import org.elasticsearch.action.admin.indices.flush.FlushResponse;
@@ -220,7 +221,7 @@ public void testIndexChunks() throws IOException {
220221

221222
AtomicInteger chunkIndex = new AtomicInteger();
222223

223-
client.addHandler(IndexAction.INSTANCE, (IndexRequest request, ActionListener<IndexResponse> listener) -> {
224+
client.addHandler(IndexAction.INSTANCE, (IndexRequest request, ActionListener<DocWriteResponse> listener) -> {
224225
int chunk = chunkIndex.getAndIncrement();
225226
assertEquals(OpType.CREATE, request.opType());
226227
assertThat(request.id(), Matchers.startsWith("test_" + (chunk + 15) + "_"));

server/src/internalClusterTest/java/org/elasticsearch/action/ListenerActionIT.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
package org.elasticsearch.action;
1010

1111
import org.elasticsearch.action.index.IndexRequest;
12-
import org.elasticsearch.action.index.IndexResponse;
1312
import org.elasticsearch.client.internal.Client;
1413
import org.elasticsearch.client.internal.Requests;
1514
import org.elasticsearch.test.ESIntegTestCase;
@@ -30,9 +29,9 @@ public void testThreadedListeners() throws Throwable {
3029
request.source(Requests.INDEX_CONTENT_TYPE, "field1", "value1");
3130
}
3231

33-
client.index(request, new ActionListener<IndexResponse>() {
32+
client.index(request, new ActionListener<DocWriteResponse>() {
3433
@Override
35-
public void onResponse(IndexResponse indexResponse) {
34+
public void onResponse(DocWriteResponse indexResponse) {
3635
threadName.set(Thread.currentThread().getName());
3736
latch.countDown();
3837
}

server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.ResourceNotFoundException;
1313
import org.elasticsearch.action.ActionFuture;
1414
import org.elasticsearch.action.ActionListener;
15+
import org.elasticsearch.action.DocWriteResponse;
1516
import org.elasticsearch.action.FailedNodeException;
1617
import org.elasticsearch.action.TaskOperationFailure;
1718
import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction;
@@ -25,7 +26,6 @@
2526
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryAction;
2627
import org.elasticsearch.action.bulk.BulkAction;
2728
import org.elasticsearch.action.index.IndexAction;
28-
import org.elasticsearch.action.index.IndexResponse;
2929
import org.elasticsearch.action.search.SearchAction;
3030
import org.elasticsearch.action.search.SearchResponse;
3131
import org.elasticsearch.action.search.SearchTransportService;
@@ -454,7 +454,7 @@ public void waitForTaskCompletion(Task task) {}
454454
}
455455
// Need to run the task in a separate thread because node client's .execute() is blocked by our task listener
456456
index = new Thread(() -> {
457-
IndexResponse indexResponse = client().prepareIndex("test").setSource("test", "test").get();
457+
DocWriteResponse indexResponse = client().prepareIndex("test").setSource("test", "test").get();
458458
assertArrayEquals(ReplicationResponse.NO_FAILURES, indexResponse.getShardInfo().getFailures());
459459
});
460460
index.start();

server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/AutoCreateSystemIndexIT.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
1616
import org.elasticsearch.action.admin.indices.template.delete.DeleteComposableIndexTemplateAction;
1717
import org.elasticsearch.action.admin.indices.template.put.PutComposableIndexTemplateAction;
18-
import org.elasticsearch.action.index.IndexResponse;
1918
import org.elasticsearch.action.support.IndicesOptions;
2019
import org.elasticsearch.cluster.metadata.AliasMetadata;
2120
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
@@ -117,7 +116,7 @@ public void testWriteToAliasPrimaryAutoCreatedFirst() throws Exception {
117116
client().execute(AutoCreateAction.INSTANCE, request).get();
118117
}
119118

120-
IndexResponse response = client().prepareIndex(INDEX_NAME).setSource("{\"foo\":\"bar\"}", XContentType.JSON).get();
119+
DocWriteResponse response = client().prepareIndex(INDEX_NAME).setSource("{\"foo\":\"bar\"}", XContentType.JSON).get();
121120
assertThat(response.getResult(), equalTo(DocWriteResponse.Result.CREATED));
122121
}
123122

@@ -136,7 +135,7 @@ public void testWriteToAliasSecondaryAutoCreatedFirst() throws Exception {
136135
client().execute(AutoCreateAction.INSTANCE, request).get();
137136
}
138137

139-
IndexResponse response = client().prepareIndex(INDEX_NAME).setSource("{\"foo\":\"bar\"}", XContentType.JSON).get();
138+
DocWriteResponse response = client().prepareIndex(INDEX_NAME).setSource("{\"foo\":\"bar\"}", XContentType.JSON).get();
140139
assertThat(response.getResult(), equalTo(DocWriteResponse.Result.CREATED));
141140
}
142141

0 commit comments

Comments
 (0)