Elasticsearch 6.2/Kibana查询:必须存在一个字段而不得存在一个字段 [英] Elasticsearch 6.2 / Kibana query: One field must exists and one field must not exists

查看:901
本文介绍了Elasticsearch 6.2/Kibana查询:必须存在一个字段而不得存在一个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的愿望是搜索存在field_a且不存在fields_b的文档. 有没有一种方法可以使用Kibana中的Lucene查询语法(Kibana的Discover部分中的Search字段).

My wish is to search docs where field_a exists, and fields_b doesn't exist. Is there a way to do this using the Lucene query syntax in Kibana (Search field in the Discover section of Kibana).

我尝试使用 _missing_:field_b 失败( _exists _ 有效).

I've tried using _missing_:field_b without success (_exists_ works).

我已经找到了,但这并没有太大帮助:

I've found this but it doesn't help much:

GET /_search
{
    "query": {
        "bool": {
            "must_not": {
                "exists": {
                    "field": "user"
                }
            }
        }
    }
}

推荐答案

Lucene搜索语法:

_exists_:field_a AND !_exists_:field_b

对于Elasticsearch搜索语法:

{
 "query" : {
  "bool" : {
   "must" : [
     {"exists" : { "field" : "field_a" }}
   ],
   "must_not": [
     {"exists" : { "field" : "field_b" }}
   ]
  }
 }
}

这篇关于Elasticsearch 6.2/Kibana查询:必须存在一个字段而不得存在一个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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