Thursday, August 25, 2016

Delete documents having a specific field with a null value in Elasticsearch

To delete documents having a specific field with a null value in Elasticsearch, install `delete-by-query` as follows:

./bin/plugin install delete-by-query

and restart the Elasticsearch.

Now you can delete them as follows:

curl -XDELETE http://localhost:9200/answer/_query?pretty -d '
{
  "query": {
    "constant_score": {
      "filter": {
        "missing": {
          "field" : "body"
        }
      }
    }
  }
}'

References:
https://www.elastic.co/guide/en/elasticsearch/plugins/current/plugins-delete-by-query.html
https://www.elastic.co/guide/en/elasticsearch/plugins/current/delete-by-query-usage.html

No comments:

Post a Comment