# Using Java High Level Rest client does not auto-retry Bulk requests

**URL:** <https://discuss.elastic.co/t/using-java-high-level-rest-client-does-not-auto-retry-bulk-requests/121724>\
**Category:** Elasticsearch\
**Created:** [February 27, 2018, 7:30pm UTC](https://discuss.elastic.co/t/using-java-high-level-rest-client-does-not-auto-retry-bulk-requests/121724 "2018-02-27T19:30:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdewald](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jdewald/32/28228_2.png) [@jdewald](https://discuss.elastic.co/u/jdewald)\
**Post date:** [February 27, 2018, 7:30pm UTC](https://discuss.elastic.co/t/using-java-high-level-rest-client-does-not-auto-retry-bulk-requests/121724/1 "2018-02-27T19:30:39Z")

</div>

This is possibly an intentional change, but there is an inconsistency in behavior when switching to using the Java High Level Rest client from the TransportClient in the case of handling of Bulk requests.

**Description of Issue**  
If the `BulkProcessor` is made to use the High Level Rest Client to issue requests, it is unable to issue retries even though it passes through the `Retry` handler's `canRetry` logic

**Steps to reproduce**  
(I can provide a repository which contains all this):

1. Create an index in ES

2. Configure the `thread_pool` to limit the bulk requests and make more likely a rejection. In my case I used a very small queue size of 2

3. Create a BulkProcessor which submits requests using `TransportClient`

4. Submit requests which result in rejection. You will find that the resulting `BulkResponse` does not contain failures, however querying the `/_cat/thread_pool` will show rejections, and the document count should have went up based on the total submitted

5. Create a BulkProcessor which submits requests using the High Level Rest client's `client.bulkAsync`method:

6. Submit requests at a rate to create rejections.

7. Perform the same set of inserts, you will find that the `BulkResponse` contains failures and the individual `Failure` objects have an `ElasticsearchException` which contains "type=es\_rejected\_execution\_exception"

**Expected Behavior**  
Failed bulk requests (from rate limiting) should get retried using the BackoffPolicy in the same way that TransportClient ones are.

It seems possible that the BulkProcessor is not currently intended to be used with the High Level Rest client, as the calls have to manually be made (versus the `TransportClient`-native builder method). However as the High Level Rest client's `bulkAsync` method produces `BulkResponses`, however this usage is demonstrated in the documentation at: [https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/java-rest-high-document-bulk.html](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/java-rest-high-document-bulk.html)

**Hypothesis of Root Issue**  
It seems that the issue stems from the change in how ElasticsearchException gets unpacked from the response. In the TransportClient version, a typed exception (such as EsRejectedExecutionExcption) gets created, and downstream logic is applied using that. However in the HLR version, it ends up as an ElasticsearchException which simply has a detail message containing a string with the "type".

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [March 2, 2018, 9:10am UTC](https://discuss.elastic.co/t/using-java-high-level-rest-client-does-not-auto-retry-bulk-requests/121724/2 "2018-03-02T09:10:21Z")

</div>

Thanks Joshua for your detailed analysis, this sounds like a bug to me. And the root is most likely what you have identified, exceptions are treated differently when using the high-level REST client as they are serialized in json format. Would you mind opening an issue in our github repo?

Thanks again  
Luca

---

<div class="post-metadata">

**Author:** ![jdewald](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jdewald/32/28228_2.png) [@jdewald](https://discuss.elastic.co/u/jdewald)\
**Post date:** [March 2, 2018, 5:03pm UTC](https://discuss.elastic.co/t/using-java-high-level-rest-client-does-not-auto-retry-bulk-requests/121724/3 "2018-03-02T17:03:56Z")

</div>

Thanks Luca! I've created a bug report (mostly copying this discussion) at: [https://github.com/elastic/elasticsearch/issues/28885](https://github.com/elastic/elasticsearch/issues/28885)

---

<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:** [March 30, 2018, 5:04pm UTC](https://discuss.elastic.co/t/using-java-high-level-rest-client-does-not-auto-retry-bulk-requests/121724/4 "2018-03-30T17:04:09Z")

</div>

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