1

我不小心从 Logstash 将一些数据加载到 Elasticsearch 中。

基本上,我忘记包含start_position => "beginning"在 Logstash 配置中,所以如果我删除.sincedb_*并重新运行,我会有一小部分重复的数据。

我使用 Kibana 来查看这些数据并单击“检查”按钮来查看它已运行的查询:

curl -XGET 'http://els-server:9200/logstash-2014.02.19,logstash-2014.02.18/_search?pretty' -d '{
  "facets": {
    "0": {
      "date_histogram": {
        "field": "@timestamp",
        "interval": "10m"
      },
      "facet_filter": {
        "fquery": {
          "query": {
            "filtered": {
              "query": {
                "query_string": {
                  "query": "tags:\"a-tag-that-uniquely-matches-the-mistake\""
                }
              },
              "filter": {
                "bool": {
                  "must": [
                    {
                      "match_all": {}
                    },
                    {
                      "range": {
                        "@timestamp": {
                          "from": 1392723206360,
                          "to": "now"
                        }
                      }
                    },
                    {
                      "bool": {
                        "must": [
                          {
                            "match_all": {}
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "size": 0
}'

如果我在 ELS 服务器上运行它,它会找到相同的结果集(如预期的那样):

{
  "took" : 23,
  "timed_out" : false,
  "_shards" : {
    "total" : 10,
    "successful" : 10,
    "failed" : 0
  },
  "hits" : {
    "total" : 558829,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "facets" : {
    "0" : {
      "_type" : "date_histogram",
      "entries" : [ {
        "time" : 1392799200000,
        "count" : 91
      } ]
    }
  }
}

该行"count" : 91匹配 Kibana 中显示的相同数量的事件。

如何将其转换为 DELETE 操作以删除这 91 个条目?

谢谢,
知识库

4

1 回答 1

3

我相信您可以在 1.0 或更高版本中通过查询删除。

单击此处查看该 API 上的 ES doco

我使用Chrome 插件 Sense针对 ES 手动运行我的查询。

例子:

DELETE /twitter/tweet/_query
{
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

在您的情况下,您应该只使用查询的查询部分:

DELETE /twitter/_search
{
"query": {
            "filtered": {
              "query": {
                "query_string": {
                  "query": "tags:\"a-tag-that-uniquely-matches-the-mistake\""
                }
              },
              "filter": {
                "bool": {
                  "must": [
                    {
                      "match_all": {}
                    },
                    {
                      "range": {
                        "@timestamp": {
                          "from": 1392723206360,
                          "to": "now"
                        }
                      }
                    },
                    {
                      "bool": {
                        "must": [
                          {
                            "match_all": {}
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            }
          }
}
于 2014-02-19T13:31:57.850 回答