Elasticsearch 2.2 : delete documents by query

标签 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 之前删除我首先找到的内容?

最佳答案

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

或者 Elastic 建议您执行查询以获取 ID,然后对结果按 ID 进行删除。

关于 Elasticsearch 2.2 : delete documents by query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35463164/

相关文章:

xml - 使用 Elasticsearch 地理功能从 XML 原始数据中查找最常见的位置

elasticsearch - 无法启动Kafka-Connect

sorting - Elasticsearch随机索引排序

elasticsearch - ElasticSearch更新API-添加以@符号开头的字段名

elasticsearch - Elasticsearch -所有父级和匹配嵌套

elasticsearch - 如何为动态索引Elasticsearch配置Kafka Connect API?

ruby-on-rails - Rails elasticsearch - 命名范围搜索

elasticsearch - 无法安装 Elasticsearch 插件

javascript - Elasticsearch .js : ReferenceError: require is not defined

indexing - Elasticsearch批量索引变慢