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.
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))
Since 7.3, the delete-by-query endpoint supports a
max_docsparameter that you can use (formerly it was calledsize).I'm not sure which version you are using, but elastic4s, the
DeleteByQueryRequestconstructor provides asizeparameter which you can use.