Search all JSON records that contain a particular attribute present using Kibana Console

495 views Asked by At

I have an Elastic Search data store where I am storing JSON data.

Say it has the following format:

{
"orderNumber": "1234"
"contactInformation": {
            "firstName": "Jane",
            "lastName" : "Doe",
            "email": "[email protected]"
           }

}

Lets say contactInformation.email is an optional attribute and the attribute itself might not occur in all records. I want to retrieve all records for which the attribute email is present. What is the query that I will use in Kibana console for this.

1

There are 1 answers

0
Amit On BEST ANSWER

You need to use the exists query

GET /_search
{
  "query": {
    "exists": {
      "field": "contactInformation.email"
    }
  }
}