Elasticsearch 6.2 / Kibana query: One field must exists and one field must not exists

主宰稳场 提交于 2019-12-08 03:04:17

问题


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).

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

回答1:


For lucene search syntax:

_exists_:field_a AND !_exists_:field_b

For elasticsearch search syntax:

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


来源:https://stackoverflow.com/questions/50996197/elasticsearch-6-2-kibana-query-one-field-must-exists-and-one-field-must-not-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!