What does max_docs do in context of _delete_by_query

Hi,

Looking at the documentation for _delete_by_query API, there is a parameter called "max_docs". From what i see it was added to documentation in 7.3.
This same parameter is shown on _reindex API documentation and has identical description

max_docs

(Optional, integer) Maximum number of documents to process. Defaults to all documents.

What i don't really understand is, what does this mean in context of _delete_by_query API? Does it mean that that is the max number of documents that will be deleted?

Main reason I'm asking is because I want to add a hard limit to our EsClient of "how many documents it's possible to delete" so that someone doesn't accidentally delete all of the data.

Easy to know:

DELETE /test
PUT /test/_doc/1
{
  "foo": "bar"
}
PUT /test/_doc/2
{
  "foo": "bar"
}
PUT /test/_doc/3
{
  "foo": "bar"
}
POST /test/_delete_by_query
{
  "max_docs": 1,
  "query": {
    "match_all": {}
  }
}
GET /test/_search?size=0

gives

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

Thanks for showing the behaviour, i get it now :slight_smile: I still feel that the documentation is ambiguous and should be more specific

Feel free to send a PR by clicking on the EDIT button in the section you want to edit. :slight_smile:

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