navigation_title: "Exists" mapped_pages:
Returns documents that contain an indexed value for a field.
An indexed value may not exist for a document’s field due to a variety of reasons:
null
or []
"index" : false
and "doc_values" : false
set in the mappingignore_above
setting in the mappingignore_malformed
was defined in the mappingGET /_search
{
"query": {
"exists": {
"field": "user"
}
}
}
exists
[exists-query-top-level-params]field
: (Required, string) Name of the field you wish to search.
While a field is deemed non-existent if the JSON value is `null` or `[]`, these values will indicate the field does exist:
* Empty strings, such as `""` or `"-"`
* Arrays containing `null` and another value, such as `[null, "foo"]`
* A custom [`null-value`](/reference/elasticsearch/mapping-reference/null-value.md), defined in field mapping
To find documents that are missing an indexed value for a field, use the must_not
boolean query with the exists
query.
The following search returns documents that are missing an indexed value for the user.id
field.
GET /_search
{
"query": {
"bool": {
"must_not": {
"exists": {
"field": "user.id"
}
}
}
}
}