I'm using Elasticsearch's bulk requests in Java and I'm trying to handle the situations where some error happens:
BulkResponse bulkResponse = bulkRequest.get();
if (bulkResponse.hasFailures()) {
for (BulkItemResponse response : bulkResponse) {
if (response.isFailed()
|| response.getResponse().getShardInfo().getFailed() > 0) {
//Find the corresponding request and resend it
}
}
}
After finding the response with error, I want to re-send its request since in my case errors could be momentary and in most of the cases a retry could resolve the problem.
So my question is, how to get from BulkItemResponse
to the original Request
that led it? Is there any way better than relying on the order of requests and responses?
No you don't have that AFAIK. You need somehow to keep all elements you added to a bulk and in case of error use the id coming from
response.getId()
to associate that with the original data.So something similar to:
I hope this helps.