# ElasticClient.DeleteByQueryAsync method is not waiting as per given Timeout

**URL:** <https://discuss.elastic.co/t/elasticclient-deletebyqueryasync-method-is-not-waiting-as-per-given-timeout/311926>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [August 11, 2022, 12:48pm UTC](https://discuss.elastic.co/t/elasticclient-deletebyqueryasync-method-is-not-waiting-as-per-given-timeout/311926 "2022-08-11T12:48:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ManElastic\_MakSearch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/manelastic_maksearch/32/109534_2.png) [@ManElastic\_MakSearch](https://discuss.elastic.co/u/ManElastic_MakSearch)\
**Post date:** [August 11, 2022, 12:48pm UTC](https://discuss.elastic.co/t/elasticclient-deletebyqueryasync-method-is-not-waiting-as-per-given-timeout/311926/1 "2022-08-11T12:48:49Z")

</div>

I am using Nest version 7.11.1. I am trying to use DeleteByQueryAsync method of ElasticClient. Below is the code I am trying to make working.

```auto
var settings = await GetConnectionSettings("XYZTenant"); //// This method sets the setting.
/*
I don't want to use below setting as it will set timeout for all my future request. As I am using the caching and returning same ElasticClient instance when needed in future.

settings.RequestTimeout(new TimeSpan(0, 10, 0)); 
*/
ElasticClient client = new ElasticClient(settings);

await client.DeleteByQueryAsync<object>(dd => dd
                    .Index(Indices.Index(indexAliases))                    
                    .Query(qd => qd.MatchAll())
                    .Conflicts(Conflicts.Proceed)                    
                    .WaitForCompletion()                    
                    .Refresh()
                    .Timeout(new Time(new TimeSpan(0, 7, 0)))
                );

```

But it's getting timeout after 60 second as I have around 2 million record to delete.  
So it is not waiting for 7 minute what I configured.  
I am not sure what I am missing. Could anyone please help me here?  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![ManElastic\_MakSearch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/manelastic_maksearch/32/109534_2.png) [@ManElastic\_MakSearch](https://discuss.elastic.co/u/ManElastic_MakSearch)\
**Post date:** [August 25, 2022, 9:33am UTC](https://discuss.elastic.co/t/elasticclient-deletebyqueryasync-method-is-not-waiting-as-per-given-timeout/311926/2 "2022-08-25T09:33:11Z")

</div>

I found a method RequestConfiguration where we can set the RequestTimeout for individual request and that worked for me.

```auto
await client.DeleteByQueryAsync<object>(dd => dd
                    .Index(Indices.Index(indexAliases))
                    .RequestConfiguration(x => x.RequestTimeout(new TimeSpan(0, 10, 0)))
                    .Query(qd => qd.MatchAll())
                    .Conflicts(Conflicts.Proceed)                    
                    .WaitForCompletion()                    
                    .Refresh()
                );

```

---

<div class="post-metadata">

**Author:** ![ManElastic\_MakSearch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/manelastic_maksearch/32/109534_2.png) [@ManElastic\_MakSearch](https://discuss.elastic.co/u/ManElastic_MakSearch)\
**Post date:** [September 7, 2022, 12:57pm UTC](https://discuss.elastic.co/t/elasticclient-deletebyqueryasync-method-is-not-waiting-as-per-given-timeout/311926/3 "2022-09-07T12:57:09Z")

</div>

Another resolution what I found, instead of deleting all the data from index, now we are deleting index itself and recreating it which is a speedy process.

---

<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:** [October 5, 2022, 12:58pm UTC](https://discuss.elastic.co/t/elasticclient-deletebyqueryasync-method-is-not-waiting-as-per-given-timeout/311926/4 "2022-10-05T12:58:06Z")

</div>

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