WARNING: Version 1.3 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Missing Filter
editMissing Filter
editReturns documents that have no non-null
values in the original field:
{ "constant_score" : { "filter" : { "missing" : { "field" : "user" } } } }
For instance, the following docs would match the above filter:
These documents would not match the above filter:
An empty string is a non- |
|
Even though the |
|
This field has one non- |
null_value
mapping
editIf the field mapping includes a null_value
(see Core Types) then explicit null
values
are replaced with the specified null_value
. For instance, if the user
field were mapped
as follows:
"user": { "type": "string", "null_value": "_null_" }
then explicit null
values would be indexed as the string _null_
, and the
the following docs would not match the missing
filter:
{ "user": null } { "user": [null] }
However, these docs—without explicit null
values—would still have
no values in the user
field and thus would match the missing
filter:
{ "user": [] } { "foo": "bar" }
existence
and null_value
parameters
editWhen the field being queried has a null_value
mapping, then the behaviour of
the missing
filter can be altered with the existence
and null_value
parameters:
{ "constant_score" : { "filter" : { "missing" : { "field" : "user", "existence" : true, "null_value" : false } } } }
-
existence
-
When the
existence
parameter is set totrue
(the default), the missing filter will include documents where the field has no values, ie:{ "user": [] } { "foo": "bar" }
When set to
false
, these documents will not be included. -
null_value
-
When the
null_value
parameter is set totrue
, the missing filter will include documents where the field contains anull
value, ie:When set to
false
(the default), these documents will not be included.
Either existence
or null_value
or both must be set to true
.
Caching
editThe result of the filter is always cached.