2015-05-05 02:27:52 -04:00
|
|
|
[[query-dsl-exists-query]]
|
2015-06-03 19:59:22 -04:00
|
|
|
=== Exists Query
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-05-07 09:22:59 -04:00
|
|
|
Returns documents that contain a value other than `null` or `[]` in a provided
|
|
|
|
field.
|
|
|
|
|
|
|
|
[[exists-query-ex-request]]
|
|
|
|
==== Example request
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[source,js]
|
2019-05-07 09:22:59 -04:00
|
|
|
----
|
2016-05-24 05:58:43 -04:00
|
|
|
GET /_search
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
2016-05-24 05:58:43 -04:00
|
|
|
"query": {
|
2019-05-07 09:22:59 -04:00
|
|
|
"exists": {
|
|
|
|
"field": "user"
|
|
|
|
}
|
2017-03-30 22:01:07 -04:00
|
|
|
}
|
|
|
|
}
|
2019-05-07 09:22:59 -04:00
|
|
|
----
|
2017-03-30 22:01:07 -04:00
|
|
|
// CONSOLE
|
2014-11-08 10:57:41 -05:00
|
|
|
|
2019-05-07 09:22:59 -04:00
|
|
|
[[exists-query-top-level-params]]
|
|
|
|
==== Top-level parameters for `exists`
|
|
|
|
`field`::
|
|
|
|
Name of the field you wish to search.
|
|
|
|
+
|
|
|
|
To return a document, this field must exist and contain a value other
|
|
|
|
than `null` or `[]`. These values can include:
|
|
|
|
+
|
|
|
|
* Empty strings, such as `""` or `"-"`
|
|
|
|
* Arrays containing `null` and another value, such as `[null, "foo"]`
|
|
|
|
* A custom <<null-value, `null-value`>>, defined in field mapping
|
|
|
|
|
|
|
|
[[exists-query-notes]]
|
|
|
|
==== Notes
|
|
|
|
|
|
|
|
[[find-docs-null-values]]
|
|
|
|
===== Find documents with null values
|
|
|
|
To find documents that contain only `null` values or `[]` in a provided field,
|
|
|
|
use the `must_not` <<query-dsl-bool-query, boolean query>> with the `exists`
|
|
|
|
query.
|
|
|
|
|
|
|
|
The following search returns documents that contain only `null` values or `[]`
|
|
|
|
in the `user` field.
|
2014-11-08 10:57:41 -05:00
|
|
|
|
|
|
|
[source,js]
|
2019-05-07 09:22:59 -04:00
|
|
|
----
|
2016-05-24 05:58:43 -04:00
|
|
|
GET /_search
|
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"bool": {
|
|
|
|
"must_not": {
|
|
|
|
"exists": {
|
|
|
|
"field": "user"
|
|
|
|
}
|
|
|
|
}
|
2015-12-10 06:55:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-07 09:22:59 -04:00
|
|
|
----
|
|
|
|
// CONSOLE
|