# Increasing scroll size in delete by query

**URL:** <https://discuss.elastic.co/t/increasing-scroll-size-in-delete-by-query/60366>\
**Category:** Elasticsearch\
**Created:** [September 13, 2016, 10:20am UTC](https://discuss.elastic.co/t/increasing-scroll-size-in-delete-by-query/60366 "2016-09-13T10:20:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kunal642](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@kunal642](https://discuss.elastic.co/u/kunal642)\
**Post date:** [September 13, 2016, 10:20am UTC](https://discuss.elastic.co/t/increasing-scroll-size-in-delete-by-query/60366/1 "2016-09-13T10:20:54Z")

</div>

Hi,  
According the the documentation the delete by query plugin is built upon the scroll and bulk API's. The size of the hits returned by scroll is 10 (by default).  
Can this size be increased?? The default setting is taking too long to delete the documents.  
If not, is there a faster way to delete the documents?

I am using the following code:-  
new DeleteByQueryRequestBuilder(esClient,DeleteByQueryAction.INSTANCE).setIndices(index).setQuery(deleteQuery)  
.get()

Thanks

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [September 13, 2016, 1:22pm UTC](https://discuss.elastic.co/t/increasing-scroll-size-in-delete-by-query/60366/2 "2016-09-13T13:22:20Z")

</div>

Pre-5.0 the parameter is named `size`, which is confusing. It is documented [here](https://www.elastic.co/guide/en/elasticsearch/plugins/current/delete-by-query-usage.html#_query_string_parameters). `10` is a very, very small default size. In the transport client you'd do something like `DeleteByQueryAction.newRequestBuilder(client).setSource(new SearchSourceBuilder().size(1000)).setIndices(index).setQuery(deleteQuery).get()`. It is a bit funky to do, sorry!

We rewrote delete-by-query to use the same infrastructure as reindex and update by query in 5.0. The parameter is named [`scroll_size`](https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete-by-query.html). In the transport client it is fairly similar to 2.x.

---

<div class="post-metadata">

**Author:** ![kunal642](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@kunal642](https://discuss.elastic.co/u/kunal642)\
**Post date:** [September 14, 2016, 6:01am UTC](https://discuss.elastic.co/t/increasing-scroll-size-in-delete-by-query/60366/3 "2016-09-14T06:01:09Z")

</div>

I tried the solution but the setSource method does not take SearchSourceBuilder as an argument. I had to apply toString on the SearchSourceBuilder to get it to work.  
But my problem still persists.  
I executed the delete query on 110k documents with the size 50k via curl and it could delete only 50k documents. It showed 60k failed.  
The next time i hit the query it shows 60k were found but deletion failed.  
I cannot the understand why it was able to delete at the first time but not on the second.

---

<div class="post-metadata">

**Author:** ![kunal642](https://avatars.discourse-cdn.com/v4/letter/k/f19dbf/32.png) [@kunal642](https://discuss.elastic.co/u/kunal642)\
**Post date:** [September 14, 2016, 11:49am UTC](https://discuss.elastic.co/t/increasing-scroll-size-in-delete-by-query/60366/4 "2016-09-14T11:49:28Z")

</div>

@nik9000  
This did the trick for me:-  
DeleteByQueryAction.INSTANCE.newRequestBuilder(client)  
.setSource(new SearchSourceBuilder().query(filters).size(10000).toString).setIndices(queryIndex).get()

The deletion is completed within couple of seconds.

Thanks for your help

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [September 14, 2016, 12:06pm UTC](https://discuss.elastic.co/t/increasing-scroll-size-in-delete-by-query/60366/5 "2016-09-14T12:06:22Z")

</div>

Yikes! I hadn't realized it didn't have an override for the actual source builder.

If this works then great. This whole thing is rewritten in 5.0 and should be much easier to work with.

---

<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:20pm UTC](https://discuss.elastic.co/t/increasing-scroll-size-in-delete-by-query/60366/6 "2017-07-05T22:20:19Z")

</div>


