# Does \_delete\_by\_query close the scroll context once it has completed or leave it to expire

**URL:** <https://discuss.elastic.co/t/does-delete-by-query-close-the-scroll-context-once-it-has-completed-or-leave-it-to-expire/347713>\
**Category:** Elasticsearch\
**Created:** [November 22, 2023, 9:45am UTC](https://discuss.elastic.co/t/does-delete-by-query-close-the-scroll-context-once-it-has-completed-or-leave-it-to-expire/347713 "2023-11-22T09:45:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![willbo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/willbo/32/127912_2.png) [@willbo](https://discuss.elastic.co/u/willbo)\
**Post date:** [November 22, 2023, 9:45am UTC](https://discuss.elastic.co/t/does-delete-by-query-close-the-scroll-context-once-it-has-completed-or-leave-it-to-expire/347713/1 "2023-11-22T09:45:08Z")

</div>

We have a spark application that needs to use `_delete_by_query` to do some cleanup after it's finished indexing during a spark task. We're finding that this is causing us to hit the scroll context limit. Our delete requests tend to return very few results so should be executed quickly which leads me to wonder about the following

- Are the scroll contexts used by `_delete_by_query` cleared after the delete is finished or left to expire naturally?
- Would a new scroll be created if the timeout was breached or would the entire request fail?

---

<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:** [December 20, 2023, 9:45am UTC](https://discuss.elastic.co/t/does-delete-by-query-close-the-scroll-context-once-it-has-completed-or-leave-it-to-expire/347713/2 "2023-12-20T09:45:24Z")

</div>

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