How to get only failed documents in the response from Elasticsearch Java High-Level Client 6.8

Viewed 612

Is there any way to get only failed documents in the response while bulk request using Elasticsearch Java High-Level REST Client.

Currently, ES is sending all the succeed and failed document in the response and we are reprocessing all the failed document, we are iterating BulkItemResponse to find the failed document and reprocessing it.

private BulkRequest createBulkRequestsForRetry(BulkResponse bulkItemResponses, BulkRequest currentBulkRequest) {
        BulkRequest bulkRequest = new BulkRequest();
        int index = 0;
        for (BulkItemResponse bulkItemResponse : bulkItemResponses.getItems()) {
            if (bulkItemResponse.isFailed()) {
                bulkRequest.add(currentBulkRequest.requests().get(index));
            }
            index++;
        }
        return bulkRequest;
    }

As bulkItemResponse.getItems() representing each action performed in the bulk operation (in the same order!).

1 Answers

As of now even in the latest 7.7 version of the client, this feature is not present, if you want this feature you can create an issue or better submit a PR addressing the issue, it would be a very useful feature to have.

You can have a look at the complete BulkResponse and see yourself there is no such functionality present in the master branch as well.

Also here you can create an issue to Elasticsearch.

Related