# Can't figure out must\_not in filtered DELETE query

**URL:** <https://discuss.elastic.co/t/cant-figure-out-must-not-in-filtered-delete-query/2069>\
**Category:** Elasticsearch\
**Created:** [June 6, 2015, 4:32pm UTC](https://discuss.elastic.co/t/cant-figure-out-must-not-in-filtered-delete-query/2069 "2015-06-06T16:32:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcel\_emblazoned](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@Marcel\_emblazoned](https://discuss.elastic.co/u/Marcel_emblazoned)\
**Post date:** [June 6, 2015, 4:32pm UTC](https://discuss.elastic.co/t/cant-figure-out-must-not-in-filtered-delete-query/2069/1 "2015-06-06T16:32:01Z")

</div>

I am trying to delete a set of documents that do not match a field with a certain value by sending the following data through a DELETE request to "localhost:9200/products/phone":

{

```
  "query": {
    "filtered": {
      "query": {
        "match_all": []
      },
      "filter": {
        "bool": {
          "must": [],
          "should": [],
          "must_not": {
            "term": {
              "batch": 1433585920
            }
          }
        }
      }
    }
  }
}

```

But this query ends up deleting ALL documents of the /products/phone type, including the documents that have the 1433586041 value in 'batch'. What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [June 8, 2015, 7:39am UTC](https://discuss.elastic.co/t/cant-figure-out-must-not-in-filtered-delete-query/2069/2 "2015-06-08T07:39:27Z")

</div>

Looks like your URL is wrong for a delete by query request. It should be in the format:

```nohighlight
http://localhost:9200/{index}/{type}/_query

```

see the following documentation link for more details ont the delete by query API: [https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html#multiple-indices](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html#multiple-indices)

---

<div class="post-metadata">

**Author:** ![dantuff](https://avatars.discourse-cdn.com/v4/letter/d/e79b87/32.png) [@dantuff](https://discuss.elastic.co/u/dantuff)\
**Post date:** [June 8, 2015, 7:42am UTC](https://discuss.elastic.co/t/cant-figure-out-must-not-in-filtered-delete-query/2069/3 "2015-06-08T07:42:34Z")

</div>

The URI in your delete by query request is not correct.

> [@Marcel\_emblazoned](#):
>
> "localhost:9200/products/phone

This will delete all documents of type `phone`. You need to specify the `_query` endpoint, i.e.

```
localhost:9200/products/phone/_query

```

More examples can be found [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html).

---

<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 6, 2017, 12:09am UTC](https://discuss.elastic.co/t/cant-figure-out-must-not-in-filtered-delete-query/2069/4 "2017-07-06T00:09:02Z")

</div>


