简体   繁体   中英

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

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.).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM