Search in sources :

Example 1 with BulkFailureException

use of org.springframework.data.elasticsearch.BulkFailureException in project spring-data-elasticsearch by spring-projects.

the class ReactiveElasticsearchTemplate method checkForBulkOperationFailure.

protected Mono<BulkResponse> checkForBulkOperationFailure(BulkResponse bulkResponse) {
    if (bulkResponse.hasFailures()) {
        Map<String, String> failedDocuments = new HashMap<>();
        for (BulkItemResponse item : bulkResponse.getItems()) {
            if (item.isFailed()) {
                failedDocuments.put(item.getId(), item.getFailureMessage());
            }
        }
        BulkFailureException exception = new BulkFailureException("Bulk operation has failures. Use ElasticsearchException.getFailedDocuments() for detailed messages [" + failedDocuments + ']', failedDocuments);
        return Mono.error(exception);
    } else {
        return Mono.just(bulkResponse);
    }
}
Also used : HashMap(java.util.HashMap) BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) BulkFailureException(org.springframework.data.elasticsearch.BulkFailureException)

Aggregations

HashMap (java.util.HashMap)1 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)1 BulkFailureException (org.springframework.data.elasticsearch.BulkFailureException)1