# How to specify "wait several N seconds before retry" in Elastic Python Client?

**URL:** <https://discuss.elastic.co/t/how-to-specify-wait-several-n-seconds-before-retry-in-elastic-python-client/360726>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [June 3, 2024, 2:56pm UTC](https://discuss.elastic.co/t/how-to-specify-wait-several-n-seconds-before-retry-in-elastic-python-client/360726 "2024-06-03T14:56:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nnikushkin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nnikushkin/32/122950_2.png) [@nnikushkin](https://discuss.elastic.co/u/nnikushkin)\
**Post date:** [June 3, 2024, 2:56pm UTC](https://discuss.elastic.co/t/how-to-specify-wait-several-n-seconds-before-retry-in-elastic-python-client/360726/1 "2024-06-03T14:56:11Z")

</div>

Hello guys!

I found that I can specify the number of attempts to retry a request if the connection is lost (below example for Python Client):

```auto
from elasticsearch import Elasticsearch
es = Elasticsearch(url, basic_auth=(user, pass), max_retries=10)

```

However, how can I specify a wait interval before such retries?

For example, if an Elasticsearch request fails, I want to retry 10 times with a `1-second` interval between requests (ideally, I would like to wait for `1 second * 2**retry_number` between retries)

I found that Elasticsearch bulk has such an option known as `initial_backoff`:

[Elasticsearch Helpers](https://elasticsearch-py.readthedocs.io/en/stable/helpers.html#elasticsearch.helpers.streaming_bulk)

However, there's nothing similar for Elasticsearch itself.

How can I achieve this?

Thank you!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 3, 2024, 4:01pm UTC](https://discuss.elastic.co/t/how-to-specify-wait-several-n-seconds-before-retry-in-elastic-python-client/360726/2 "2024-06-03T16:01:06Z")

</div>

I don't know if it's possible but I'm wondering why you'd like it to be "slow"...  
In a multi-node cluster which is what you should have in production, you should never ever have such a problem as one of the nodes should be able to be queried.

So I'm wondering why you would like to have such a behavior?

---

<div class="post-metadata">

**Author:** ![nnikushkin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nnikushkin/32/122950_2.png) [@nnikushkin](https://discuss.elastic.co/u/nnikushkin)\
**Post date:** [June 3, 2024, 4:34pm UTC](https://discuss.elastic.co/t/how-to-specify-wait-several-n-seconds-before-retry-in-elastic-python-client/360726/3 "2024-06-03T16:34:47Z")

</div>

@dadoonet, indeed, however, "should" does not mean "must". Retry mechanism in this situation will help to achieve this "must"

---

<div class="post-metadata">

**Author:** ![nnikushkin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nnikushkin/32/122950_2.png) [@nnikushkin](https://discuss.elastic.co/u/nnikushkin)\
**Post date:** [June 3, 2024, 6:14pm UTC](https://discuss.elastic.co/t/how-to-specify-wait-several-n-seconds-before-retry-in-elastic-python-client/360726/4 "2024-06-03T18:14:30Z")

</div>

To add here

@dadoonet, I would say that due to the current network setup, there could be a situation that all my nodes are not available for a small amount of time

If so, the data failed to be delivered to Elastic, however, any retry could help me here

Thus, I asked

Thank you!

---

<div class="post-metadata">

**Author:** ![Quentin\_Pradet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/quentin_pradet/32/94192_2.png) [@Quentin\_Pradet](https://discuss.elastic.co/u/Quentin_Pradet)\
**Post date:** [June 10, 2024, 1:14pm UTC](https://discuss.elastic.co/t/how-to-specify-wait-several-n-seconds-before-retry-in-elastic-python-client/360726/5 "2024-06-10T13:14:38Z")

</div>

Hello, this is not possible using the Python client, but it would be a good enhancement to add.

---

<div class="post-metadata">

**Author:** ![nnikushkin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nnikushkin/32/122950_2.png) [@nnikushkin](https://discuss.elastic.co/u/nnikushkin)\
**Post date:** [June 10, 2024, 1:51pm UTC](https://discuss.elastic.co/t/how-to-specify-wait-several-n-seconds-before-retry-in-elastic-python-client/360726/6 "2024-06-10T13:51:23Z")

</div>

Hey @Quentin_Pradet,

Thank you for the confirmation!

Is there any bug/feature ID, so I can subscribe to it, or should I create a new bug/feature request myself?

Thanks!

---

<div class="post-metadata">

**Author:** ![Quentin\_Pradet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/quentin_pradet/32/94192_2.png) [@Quentin\_Pradet](https://discuss.elastic.co/u/Quentin_Pradet)\
**Post date:** [September 24, 2024, 5:29pm UTC](https://discuss.elastic.co/t/how-to-specify-wait-several-n-seconds-before-retry-in-elastic-python-client/360726/7 "2024-09-24T17:29:51Z")

</div>

Hello, and sorry for the delay. You can follow this issue: [`retry_on_status` setting does not work as expected with requests that should not be retried immediately · Issue #2485 · elastic/elasticsearch-py · GitHub](https://github.com/elastic/elasticsearch-py/issues/2485).
