# What does max\_docs do in context of \_delete\_by\_query

**URL:** https://discuss.elastic.co/t/what-does-max-docs-do-in-context-of-delete-by-query/256317
**Category:** Elasticsearch
**Created:** [November 23, 2020, 7:54am UTC](https://discuss.elastic.co/t/what-does-max-docs-do-in-context-of-delete-by-query/256317 "2020-11-23T07:54:35Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![vangogh94](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vangogh94/32/48826_2.png) [@vangogh94](https://discuss.elastic.co/u/vangogh94)
#### Post date: [November 23, 2020, 7:54am UTC](https://discuss.elastic.co/t/what-does-max-docs-do-in-context-of-delete-by-query/256317/1 "2020-11-23T07:54:35Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [November 23, 2020, 8:54am UTC](https://discuss.elastic.co/t/what-does-max-docs-do-in-context-of-delete-by-query/256317/2 "2020-11-23T08:54:26Z")

</div>

Easy to know:

```auto
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

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

```

---

<div class="post-metadata">

### Author: ![vangogh94](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vangogh94/32/48826_2.png) [@vangogh94](https://discuss.elastic.co/u/vangogh94)
#### Post date: [November 23, 2020, 10:25am UTC](https://discuss.elastic.co/t/what-does-max-docs-do-in-context-of-delete-by-query/256317/3 "2020-11-23T10:25:56Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [November 23, 2020, 10:53am UTC](https://discuss.elastic.co/t/what-does-max-docs-do-in-context-of-delete-by-query/256317/4 "2020-11-23T10:53:41Z")

</div>

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

---

<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 21, 2020, 10:54am UTC](https://discuss.elastic.co/t/what-does-max-docs-do-in-context-of-delete-by-query/256317/5 "2020-12-21T10:54:02Z")

</div>

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