Marki
Marki

Reputation: 661

Elasticsearch 2.2: delete documents by query

I am trying to delete some documents from Elasticsearch.

I have these requests:

IDX=logstash-2016.02.13

curl -XGET "http://localhost:9200/$IDX/fg400/_search" -d '{
  "query" : {
    "term" : {
      "action" : "start"
    }
  }
}' | python -m json.tool

This read query gives:

{
    "_shards": {
        "failed": 0,
        "successful": 5,
        "total": 5
    },
    "hits": {
        "hits": [
            {
                "_id": "AVLcXJrLLFxTvjNEoqDO",
                "_index": "logstash-2016.02.13",
                "_score": 3.4307306,
                "_source": {
                    "@timestamp": "2016-02-13T20:40:00.000Z",
                    "@version": "1",
                    "action": "start",   <------
...
        ],
        "max_score": 3.4307306,
        "total": 146511
    },
    "timed_out": false,
    "took": 13
}

Now I say this because I want to DELETE some:

curl -XDELETE "http://localhost:9200/${IDX}/fg400/_query" -d '{
  "query" : {
    "term" : {
        "action" : "start"
    }
  }
}' | python -m json.tool

And this gives the following output:

{
    "_id": "_query",
    "_index": "logstash-2016.02.13",
    "_shards": {
        "failed": 0,
        "successful": 1,
        "total": 2
    },
    "_type": "fg400",
    "_version": 1,
    "found": false
}

Why can't I delete what I found in the first place before using GET?

Upvotes: 4

Views: 3307

Answers (1)

sksamuel
sksamuel

Reputation: 16387

Delete by query was turned into a plugin in 2.0 onwards. In order to use this functionality you will need to install the plugin https://www.elastic.co/guide/en/elasticsearch/plugins/2.2/delete-by-query-usage.html

Or what Elastic recommend is you do a query to get the ids, then do a delete by id on the results.

Upvotes: 3

Related Questions