【问题标题】:Elasticsearch 6.2 / Kibana query: One field must exists and one field must not existsElasticsearch 6.2 / Kibana 查询:一个字段必须存在,一个字段不能存在
【发布时间】:2018-12-02 10:03:33
【问题描述】:

我的愿望是搜索 field_a 存在且 fields_b 不存在的文档。 有没有办法使用 Kibana 中的 Lucene 查询语法(Kibana 的 Discover 部分中的 Search 字段)来做到这一点。

我尝试使用 _missing_:field_b 没有成功(_exists_ 有效)。

我找到了这个,但没有多大帮助:

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

【问题讨论】:

    标签: elasticsearch lucene kibana exists not-exists


    【解决方案1】:

    对于 lucene 搜索语法:

    _exists_:field_a AND !_exists_:field_b

    对于 elasticsearch 搜索语法:

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

    【讨论】:

      猜你喜欢
      • 2019-09-18
      • 2020-02-15
      • 1970-01-01
      • 1970-01-01
      • 2017-12-29
      • 2019-03-06
      • 2015-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多