简体   繁体   English

ElasticSearch如何删除文档(如果字段存在)?

[英]ElasticSearch how to DELETE docs if field exists?

I want to delete all documents where a certain field exists 我想删除存在某个字段的所有文档

I tried to POST to the _delete_by_query API 我试图过_delete_by_query API

{
  "query": { 
    "bool": {
      "must": [
        { "exists":"field_name" }
      ]
    }
  }
}

That's giving me this query malformed error: 这给了我这个查询格式错误:

{
"error": {
    "root_cause": [
        {
            "type": "parsing_exception",
            "reason": "[exists] query malformed, no start_object after query name",
            "line": 1,
            "col": 37
        }
    ],
    "type": "parsing_exception",
    "reason": "[exists] query malformed, no start_object after query name",
    "line": 1,
    "col": 37
},
"status": 400
}

How can I delete all docs if field exists? 如果字段存在,如何删除所有文档?

There is an error in your query: 您的查询中有一个错误:

You don't have to use bool query, just use below query and it should work. 您不必使用bool查询,只需使用以下查询即可。

{
"query": {
  "exists": {
    "field": "name"
  }
 }
}

Read this for more details. 阅读以获得更多详细信息。

Hope this helps!! 希望这可以帮助!!

You do not need to wrap the exists in a bool. 您无需将存在的内容包装在布尔中。 Try this 尝试这个

 {
  "query": { 
    "exists": {
      "field": "field_name"
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM