# Elastic Delete Docs not waiting

**URL:** <https://discuss.elastic.co/t/elastic-delete-docs-not-waiting/47217>\
**Category:** Elasticsearch\
**Created:** [April 13, 2016, 8:42am UTC](https://discuss.elastic.co/t/elastic-delete-docs-not-waiting/47217 "2016-04-13T08:42:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rdehuyss](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rdehuyss/32/83278_2.png) [@rdehuyss](https://discuss.elastic.co/u/rdehuyss)\
**Post date:** [April 13, 2016, 8:42am UTC](https://discuss.elastic.co/t/elastic-delete-docs-not-waiting/47217/1 "2016-04-13T08:42:28Z")

</div>

Hi,

We have some integration tests where we also use Elastic.

Before each test, we delete all the documents using the NEST api. However, we sometimes see that the documents are not deleted yet - it appears as the delete call is non-blocking and returns before the actual delete is complete.

Below some code that reproduces the issue:

`var searchResponse = ElasticClient.Search<AidaLegitimatiekaartReadModel>(q => q.Type<AidaLegitimatiekaartReadModel>()); foreach (var aidaLegitimatiekaartReadModel in searchResponse.Hits) { ElasticClient.Delete<AidaLegitimatiekaartReadModel>(aidaLegitimatiekaartReadModel.Id); } var after = ElasticClient.Search<AidaLegitimatiekaartReadModel>(q => q.Type<AidaLegitimatiekaartReadModel>()); after.Hits.Should().BeEmpty(); // => BOEM!`

An error is thrown on the last line of the provided code block.

We're using ES v2.2.1 and Nest v2.0.2

Any idea what are we doing wrong?

Thanks in advance,  
Ronald

---

<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:** [April 13, 2016, 8:54am UTC](https://discuss.elastic.co/t/elastic-delete-docs-not-waiting/47217/2 "2016-04-13T08:54:03Z")

</div>

You have to refresh the index before searching.

---

<div class="post-metadata">

**Author:** ![rdehuyss](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rdehuyss/32/83278_2.png) [@rdehuyss](https://discuss.elastic.co/u/rdehuyss)\
**Post date:** [April 13, 2016, 9:22am UTC](https://discuss.elastic.co/t/elastic-delete-docs-not-waiting/47217/3 "2016-04-13T09:22:56Z")

</div>

Wauw, thanks for the fast reply. Didn't think of that!

---

<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 5, 2017, 10:59pm UTC](https://discuss.elastic.co/t/elastic-delete-docs-not-waiting/47217/4 "2017-07-05T22:59:41Z")

</div>


