# \[Spring Data Elasticsearch\] Exception during save regardless of success

**URL:** <https://discuss.elastic.co/t/spring-data-elasticsearch-exception-during-save-regardless-of-success/306813>\
**Category:** Elasticsearch\
**Created:** [June 9, 2022, 3:47pm UTC](https://discuss.elastic.co/t/spring-data-elasticsearch-exception-during-save-regardless-of-success/306813 "2022-06-09T15:47:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Almost\_Familiar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/almost_familiar/32/97757_2.png) [@Almost\_Familiar](https://discuss.elastic.co/u/Almost_Familiar)\
**Post date:** [June 9, 2022, 3:47pm UTC](https://discuss.elastic.co/t/spring-data-elasticsearch-exception-during-save-regardless-of-success/306813/1 "2022-06-09T15:47:38Z")

</div>

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](https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.reactive.operations).

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

```auto
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:

```auto
 {
  "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:

 ![Bildschirmfoto 2022-06-09 um 17.43.20](https://us1.discourse-cdn.com/elastic/original/3X/4/a/4a40eb5be5214235179693e005e2b52c3aae4eaf.png)

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

---

<div class="post-metadata">

**Author:** ![Almost\_Familiar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/almost_familiar/32/97757_2.png) [@Almost\_Familiar](https://discuss.elastic.co/u/Almost_Familiar)\
**Post date:** [June 9, 2022, 3:59pm UTC](https://discuss.elastic.co/t/spring-data-elasticsearch-exception-during-save-regardless-of-success/306813/2 "2022-06-09T15:59:21Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 7, 2022, 4:00pm UTC](https://discuss.elastic.co/t/spring-data-elasticsearch-exception-during-save-regardless-of-success/306813/3 "2022-07-07T16:00:17Z")

</div>

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