Quentin
Quentin

Reputation: 701

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

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

Upvotes: 2

Views: 1769

Answers (1)

TechnocratSid
TechnocratSid

Reputation: 2415

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

Upvotes: 3

Related Questions