【问题标题】:How can I delete all the documents in an elasticsearch index that does not contain a specific value?如何删除弹性搜索索引中不包含特定值的所有文档?
【发布时间】:2018-02-22 06:52:59
【问题描述】:

我的文档包含各种字段,例如(时间戳、metric_name 等)。 我想删除所有metric_name字段不匹配cpu/timequery/time的文档。

【问题讨论】:

标签: elasticsearch


【解决方案1】:

如果删除的记录比较多,千万不要错过运行 forcemerge 彻底删除。 按查询删除只是将它们标记为已删除而不是删除它们

【讨论】:

  • 是的,当我看到删除文档后索引大小仍然相同时,我就明白了。谢谢!
【解决方案2】:

您只需在_delete_by_query下方POST

POST <put_your_index_name_here>/_delete_by_query
{
  "query": {
    "bool": {
      "must_not": [{
        "terms": {
          "metric_name.keyword": ["cpu/time","query/time"]
        }
      }]
    }
  }
}

资源:

【讨论】:

  • 感谢您的回复。尝试了另一种方法(在下面发布)。
【解决方案3】:

我也想出了以下方法。

POST /_delete_by_query

{
"query": {
    "bool": {
        "must_not": [{
            "bool": {
                "should": [{
                        "match_phrase": {
                            "metric": "cpu/time"
                        }
                    },
                    {
                        "match_phrase": {
                            "metric": "query/time"
                        }
                    }
                ],
                "minimum_should_match": 1
            }
        }]
    }
}

}

ma​​tch_phrase 有效,因为在其他指标中没有匹配前缀

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-30
    • 2015-11-02
    • 2018-07-17
    相关资源
    最近更新 更多