ElasticSearch如何删除文档(如果字段存在)? [英] ElasticSearch how to DELETE docs if field exists?

查看:70
本文介绍了ElasticSearch如何删除文档(如果字段存在)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要删除存在某个字段的所有文档

I want to delete all documents where a certain field exists

我试图过帐到 _delete_by_query API

I tried to POST to the _delete_by_query API

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

这给了我这个格式错误的查询 :

{
"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
}

如果 field 存在,如何删除所有文档?

How can I delete all docs if field exists?

推荐答案

查询中存在错误:

您不必使用 bool 查询,只需使用以下查询,它便可以正常工作.

You don't have to use bool query, just use below query and it should work.

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

阅读了解更多信息.

希望这会有所帮助!

这篇关于ElasticSearch如何删除文档(如果字段存在)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆