Can't figure out must_not in filtered DELETE query


(Marcel Emblazoned) #1

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?


(Colin Goodheart-Smithe) #2

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

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


(Dan Tuffery) #3

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

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.


(system) #4