elasticsearch/docs/reference/query-languages/query-dsl/query-dsl-exists-query.md
Craig Taverner 94cad286bc
Restructure query-languages docs files for clarity (#124797)
In a few previous PR's we restructured the ES|QL docs to make it possible to generate them dynamically.

This PR just moves a few files around to make the query languages docs easier to work with, and a little more organized like the ES|QL docs.

A bit part of this was setting up redirects to the new locations, so other repo's could correctly link to the elasticsearch docs.
2025-03-17 17:58:58 +01:00

70 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
navigation_title: "Exists"
mapped_pages:
- https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html
---
# Exists query [query-dsl-exists-query]
Returns documents that contain an indexed value for a field.
An indexed value may not exist for a documents field due to a variety of reasons:
* The field in the source JSON is `null` or `[]`
* The field has `"index" : false` and `"doc_values" : false` set in the mapping
* The length of the field value exceeded an `ignore_above` setting in the mapping
* The field value was malformed and `ignore_malformed` was defined in the mapping
## Example request [exists-query-ex-request]
```console
GET /_search
{
"query": {
"exists": {
"field": "user"
}
}
}
```
## Top-level parameters for `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
## Notes [exists-query-notes]
### Find documents missing indexed values [find-docs-null-values]
To find documents that are missing an indexed value for a field, use the `must_not` [boolean query](/reference/query-languages/query-dsl/query-dsl-bool-query.md) with the `exists` query.
The following search returns documents that are missing an indexed value for the `user.id` field.
```console
GET /_search
{
"query": {
"bool": {
"must_not": {
"exists": {
"field": "user.id"
}
}
}
}
}
```