Skip to content

Reactive saveAll does not report bulk failures of documents without an id #3369

Closed

Description

@Ridzzz0Alam

Issue

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

{"errors":true,"items":[{"index":{"_id":null,"status":400,"error":{"type":"index_closed_exception", ...}}}]}

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()) {
	return Mono.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

  1. Create an entity without an id (@Id property is null).
  2. 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

  1. added
    type: bug
    and removed
    status: waiting-for-triage
    on Nov 1, 2026
  2. added theissue type on Nov 1, 2026
  3. sothawo commented on Nov 1, 2026

    @sothawo
    Collaborator

    I'd like to submit a PR with a reactive integration test, if that's fine.
    please go ahead 😄

  4. added a commit that references this issue on Nov 4, 2026
    c72d892
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions