Hello,
I was working on a failure handling scenario, picture a stream of events being written to elasticsearch. If there is a failure, I take the failure and the document and store it in a safe place.
To do this I was using the BulkResponse to get any items that were marked as failed. Then gathering the original document that was attempted form the BulkRequest requests collection. All works fine for our main use case, for a MappingParseException. However if the index was closed when trying to write to it, then I am seeing code in the TransportBulkAction class that sets the request object to null:
private boolean addFailureIfIndexIsUnavailable(DocumentRequest request, BulkRequest bulkRequest, .... )
....
if(unavailableException != null) {
Failure failure1 = new Failure(request.index(), request.type(), request.id(), unavailableException);
String operationType = "unknown";
if(request instanceof IndexRequest) {
operationType = "index";
} else if(request instanceof DeleteRequest) {
operationType = "delete";
} else if(request instanceof UpdateRequest) {
operationType = "update";
}
BulkItemResponse bulkItemResponse = new BulkItemResponse(idx, operationType, failure1);
responses.set(idx, bulkItemResponse);
// make sure the request gets never processed again
bulkRequest.requests.set(idx, (Object)null);
return true;
} else {
return false;
}
This of course essentially wiped out the original document I was trying to write. I have worked around this by holding a map of the documents when building the batch. But I was curious as to why, seems to me you want to retain the original request and mark it attempted or link the failure response to the request (so that its not processed again)
I do see this similar pattern when trying to create an index as well.
Lasty, this is Elasticsearch 2.1.1
Thanks