ElasticSearch,完全匹配DELETE文档(5.1)

时间:2018-04-26 21:31:13

标签: elasticsearch

我需要删除与弹性搜索查询中的键完全匹配的信息,但是我对请求有问题,并且删除了具有相同前缀的信息。我需要做些什么来修复我的脚本并只删除正确的脚本? (两个条件下的完全匹配)

curl -X POST elasticDomain/index/_delete_by_query -d '{"query": {
"bool": {
  "must": [
    {
      "term": {
        "component.name": {
          "query" : "prefix-component-one"
        }
      }
    },
    {
      "term": {
        "enviroment": "qa"
      }
    }
  ]
}}}'

数据示例,当我只想删除有关组件1的信息时:

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 1,
    "hits": [
      {
        "_index": "index",
        "_type": "event",
        "_id": "c04b0f94-4995-11e8-a9f5-a22f517abdda",
        "_score": 1,
        "_source": {
          "component": {
            "name": "prefix-component-two",
            "qualifier": "TRK"
          },

          "enviroment": "history",
          "timestamp": "2018-04-26T16:06:54.000Z"
        }
      },
      {
        "_index": "index",
        "_type": "event",
        "_id": "bf80d63e-4995-11e8-a9f5-a22f517abdda",
        "_score": 1,
        "_source": {
          "component": {
            "name": "prefix-component-one",
            "qualifier": "TRK"
          },

          "enviroment": "qa",
          "timestamp": "2018-04-26T16:06:54.000Z"
        }
      }
    ]
  }
}

1 个答案:

答案 0 :(得分:0)

我用 match_phrase

修复了
curl -X POST elasticDomain/index/_delete_by_query -d '{"query": {
"bool": {
  "must": [
    {
      "match_phrase": {
        "component.name": {
          "query" : "prefix-component-one"
        }
      }
    },
    {
      "term": {
        "enviroment": "qa"
      }
    }
  ]
}}}