diff --git a/server/src/main/java/org/elasticsearch/action/bulk/BulkPrimaryExecutionContext.java b/server/src/main/java/org/elasticsearch/action/bulk/BulkPrimaryExecutionContext.java index 85ce28d2d52db..5f61d90d500e7 100644 --- a/server/src/main/java/org/elasticsearch/action/bulk/BulkPrimaryExecutionContext.java +++ b/server/src/main/java/org/elasticsearch/action/bulk/BulkPrimaryExecutionContext.java @@ -290,10 +290,10 @@ public void markOperationAsExecuted(Engine.Result result) { /** finishes the execution of the current request, with the response that should be returned to the user */ public void markAsCompleted(BulkItemResponse translatedResponse) { assertInvariants(ItemProcessingState.EXECUTED); - assert executionResult == null || translatedResponse.getItemId() == executionResult.getItemId(); + assert executionResult != null && translatedResponse.getItemId() == executionResult.getItemId(); assert translatedResponse.getItemId() == getCurrentItem().id(); - if (translatedResponse.isFailed() == false && requestToExecute != getCurrent()) { + if (translatedResponse.isFailed() == false && requestToExecute != null && requestToExecute != getCurrent()) { request.items()[currentIndex] = new BulkItemRequest(request.items()[currentIndex].id(), requestToExecute); } getCurrentItem().setPrimaryResponse(translatedResponse); diff --git a/server/src/test/java/org/elasticsearch/action/IndicesRequestIT.java b/server/src/test/java/org/elasticsearch/action/IndicesRequestIT.java index bf28dc2ae90e8..40795bff730e0 100644 --- a/server/src/test/java/org/elasticsearch/action/IndicesRequestIT.java +++ b/server/src/test/java/org/elasticsearch/action/IndicesRequestIT.java @@ -284,7 +284,6 @@ public void testUpdateDelete() { assertSameIndices(updateRequest, updateShardActions); } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/32808") public void testBulk() { String[] bulkShardActions = new String[]{BulkAction.NAME + "[s][p]", BulkAction.NAME + "[s][r]"}; interceptTransportActions(bulkShardActions); diff --git a/server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java b/server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java index e60ee1395a858..ca19dcc250948 100644 --- a/server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java @@ -472,6 +472,8 @@ public void testNoopUpdateRequest() throws Exception { assertThat(primaryResponse.getResponse(), equalTo(noopUpdateResponse)); assertThat(primaryResponse.getResponse().getResult(), equalTo(DocWriteResponse.Result.NOOP)); + assertThat(bulkShardRequest.items().length, equalTo(1)); + assertEquals(primaryRequest, bulkShardRequest.items()[0]); // check that bulk item was not mutated assertThat(primaryResponse.getResponse().getSeqNo(), equalTo(SequenceNumbers.UNASSIGNED_SEQ_NO)); }