# Pass batch size in deleteByQuery \[elasticsearch\] \[scala\]

**URL:** <https://discuss.elastic.co/t/pass-batch-size-in-deletebyquery-elasticsearch-scala/253067>\
**Category:** Elasticsearch\
**Created:** [October 22, 2020, 8:46pm UTC](https://discuss.elastic.co/t/pass-batch-size-in-deletebyquery-elasticsearch-scala/253067 "2020-10-22T20:46:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Priya3](https://avatars.discourse-cdn.com/v4/letter/p/35a633/32.png) [@Priya3](https://discuss.elastic.co/u/Priya3)\
**Post date:** [October 22, 2020, 8:46pm UTC](https://discuss.elastic.co/t/pass-batch-size-in-deletebyquery-elasticsearch-scala/253067/1 "2020-10-22T20:46:03Z")

</div>

I need to pass batch size while using deletebyQuery.

My requirement is:

- Get x rows based on filters
- Run DeletebyQuery on them
- Return this list

While doing search using filters, there can 1000 rows but I need only batch of top 100. Need to return these 100 rows and run deleteByQuery, only on these 100.

What is the way to do this?

Here is the code of what I tried, but it ended up deleting all 1000 rows.

```auto
val searchQuery =
  search(Index.name)
  .size(100)
    .query(boolQuery.should(
      termQuery(Type.status, Type.state)))

 getElasticsearchClient().execute(searchQuery)

 val result = elasticsearchClient().execute (
    deleteByQuery(Index.name, Index.typeName,
      boolQuery.should(termQuery(Type.status, Type.state))).size(100))

```

size will be supported until ES version 8 but it doesnt seem to respect the size I pass.

---

<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:** [November 19, 2020, 8:46pm UTC](https://discuss.elastic.co/t/pass-batch-size-in-deletebyquery-elasticsearch-scala/253067/2 "2020-11-19T20:46:12Z")

</div>

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