Elasticsearch 2.2:通过查询删除文档

时间:2016-02-17 17:06:33

标签: elasticsearch

我正在尝试从Elasticsearch中删除一些文档。

我有这些要求:

IDX=logstash-2016.02.13

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

此读取查询给出:

{
    "_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
}

现在我说这是因为我想删除一些:

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

这给出了以下输出:

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

为什么在使用GET之前我不能删除我在第一时间找到的内容?

1 个答案:

答案 0 :(得分:3)

按查询删除在2.0以后变成了插件。要使用此功能,您需要安装插件 https://www.elastic.co/guide/en/elasticsearch/plugins/2.2/delete-by-query-usage.html

或者Elastic建议你做一个查询来获取id,然后在结果上按id删除。

相关问题