# Refresh sync or async?

**URL:** <https://discuss.elastic.co/t/refresh-sync-or-async/99971>\
**Category:** Elasticsearch\
**Created:** [September 10, 2017, 12:17pm UTC](https://discuss.elastic.co/t/refresh-sync-or-async/99971 "2017-09-10T12:17:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![moren](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@moren](https://discuss.elastic.co/u/moren)\
**Post date:** [September 10, 2017, 12:17pm UTC](https://discuss.elastic.co/t/refresh-sync-or-async/99971/1 "2017-09-10T12:17:27Z")

</div>

Hi, i don't understand how it should work. It doesn't matter what value the 'refresh' param have (true, wait\_for), but right after \_delete\_by\_query the search request get all the deleted documents. It's a bug or feature?

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [September 11, 2017, 12:55am UTC](https://discuss.elastic.co/t/refresh-sync-or-async/99971/2 "2017-09-11T00:55:18Z")

</div>

Are you also waiting for the completion of `_delete_by_query` i.e. specifying [`wait_for_completion=true`](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html#_url_parameters)? If you're not, then the operation will be running asynchronously. If you need to ensure that a subsequent search request does not retrieve documents that will be deleted, you can either

- specify `wait_for_completion=true` and `refresh=wait_for` and wait for the delete by query to finish before issuing the search request

or

- issue the delete by query request with `refresh=wait_for` and monitor the status of the operation with the [Tasks API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html#docs-delete-by-query-task-api), issuing the search request after it has finished

---

<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 9, 2017, 12:55am UTC](https://discuss.elastic.co/t/refresh-sync-or-async/99971/3 "2017-10-09T00:55:30Z")

</div>

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