You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reactive saveAll does not report bulk failures of documents without an id #3369
The reactive template does not return an error when a bulk request fails for a document that has no id. saveAll emits the entity as if it was saved. The imperative template throws a BulkFailureException in the same case.
When Elasticsearch rejects a document before it generates an id, the bulk response item has "_id": null. This happens for example when the index is closed, when it does not exist and action.auto_create_index is false or when the index name is invalid. I have checked with Elasticsearch 9.5.5
ReactiveElasticsearchTemplate.checkForBulkOperationFailure only collects failed items that have an id and returns an error only if it collected one
if (item.error() != null && item.id() != null) {
failedDocuments.put(item.id(), ...);
}
...
if (!failedDocuments.isEmpty()) {
returnMono.error(exception);
}
So when all failed items have no id the failure is dropped. ElasticsearchTemplate.checkForBulkOperationFailure throws whenever bulkResponse.errors() is true. The item.id() != null check came in with the nullability changes in #3282 (8ad2e8e) but before that the reactive template also returned an error whenever bulkResponse.errors() was true.
Steps to reproduce
Create an entity without an id (@Id property is null).
Call reactiveElasticsearchOperations.saveAll(Mono.just(List.of(entity)), IndexCoordinates.of("Invalid-Index-Name")) (or save to a closed index).
Expected
The returned Flux terminates with a BulkFailureException, as ElasticsearchOperations.save(Iterable) throws one.
Actual
The Flux emits the entity (with a null id) and completes. After-save callbacks are called for it.
Affects 6.1.x and main (checked on 62775da) and 6.0.x is not affected.
Suggested fix
Return the BulkFailureException when any bulk response has errors() as the imperative template does and keep collecting the failed items that have an id for getFailedDocuments()
if (bulkResponses.stream().anyMatch(BulkResponse::errors)) {
I'd like to submit a PR with a reactive integration test, if that's fine.
Activity
sothawo commentedon Nov 1, 2026
Report reactive bulk failures of documents without an id.