[Spring Data Elasticsearch] Exception during save regardless of success

Hello everyone,

we are using version Spring Boot 2.7.0 with Spring Data Elasticsearch, with reactive code.

We prefer to make our requests with native queries via the ReactiveElasticsearchOperations interface.

For an integration test we want to save a bunch of documents like this:

try {
    val saved = reactiveElasticsearchOperations.saveAll(
        listOf(product1, product2),
        indexCoordinates
    )

    saved.collectList().awaitSingle()
} catch (e: Exception ) {
    // I don't even know wtf is happening
    println(e.message)
}

This code fails with with the following error:

Error while bulk for request: org.elasticsearch.action.bulk.BulkRequest/unset

With status 200 and the cause of:

 {
  "took": 86,
  "errors": false,
  "items": [
    {
      "index": {
        "_index": "it-products-7f1c564e-e902-4833-aaf5-6c748f782502_de",
        "_id": "LwMZSYEB3U589fGcFi5U",
        "_version": 1,
        "result": "created",
        "_shards": {
          "total": 2,
          "successful": 1,
          "failed": 0
        },
        "_seq_no": 0,
        "_primary_term": 1,
        "status": 201
      }
    },
    {
      "index": {
        "_index": "it-products-7f1c564e-e902-4833-aaf5-6c748f782502_de",
        "_id": "MAMZSYEB3U589fGcFi5U",
        "_version": 1,
        "result": "created",
        "_shards": {
          "total": 2,
          "successful": 1,
          "failed": 0
        },
        "_seq_no": 1,
        "_primary_term": 1,
        "status": 201
      }
    }
  ]
}

As you can see the saves succeed with code 200 and everything works fine, except that this exception gets thrown. The documents also exist in that index.

The type of the exception is RestStatusException wrapped in UncategorizedElasticsearchException.
See the debugger at the println line in the code above:

Does anyone know what we are doing wrong here?
Thanks for your help!

Of course I found the solution immediately after making this post, after being stuck at this for hours.

The solution is to call the code as suggested in the docs. We forgot to add the .subscribe call:

reactiveElasticsearchOperations.saveAll(
    listOf(productDTO1, productDTO2),
    indexCoordinates
).doOnNext(System.out::println).subscribe()

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.