1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
[[query-dsl-missing-filter]]
=== Missing Filter
Returns documents that have only `null` values or no value in the original field:
[source,js]
--------------------------------------------------
{
"constant_score" : {
"filter" : {
"missing" : { "field" : "user" }
}
}
}
--------------------------------------------------
For instance, the following docs would match the above filter:
[source,js]
--------------------------------------------------
{ "user": null }
{ "user": [] } <1>
{ "user": [null] } <2>
{ "foo": "bar" } <3>
--------------------------------------------------
<1> This field has no values.
<2> This field has no non-`null` values.
<3> The `user` field is missing completely.
These documents would *not* match the above filter:
[source,js]
--------------------------------------------------
{ "user": "jane" }
{ "user": "" } <1>
{ "user": "-" } <2>
{ "user": ["jane"] }
{ "user": ["jane", null ] } <3>
--------------------------------------------------
<1> An empty string is a non-`null` value.
<2> Even though the `standard` analyzer would emit zero tokens, the original field is non-`null`.
<3> This field has one non-`null` value.
[float]
==== `null_value` mapping
If the field mapping includes a `null_value` (see <<mapping-core-types>>) then explicit `null` values
are replaced with the specified `null_value`. For instance, if the `user` field were mapped
as follows:
[source,js]
--------------------------------------------------
"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:
[source,js]
--------------------------------------------------
{ "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:
[source,js]
--------------------------------------------------
{ "user": [] }
{ "foo": "bar" }
--------------------------------------------------
[float]
===== `existence` and `null_value` parameters
When 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:
[source,js]
--------------------------------------------------
{
"constant_score" : {
"filter" : {
"missing" : {
"field" : "user",
"existence" : true,
"null_value" : false
}
}
}
}
--------------------------------------------------
`existence`::
+
--
When the `existence` parameter is set to `true` (the default), the missing
filter will include documents where the field has *no* values, ie:
[source,js]
--------------------------------------------------
{ "user": [] }
{ "foo": "bar" }
--------------------------------------------------
When set to `false`, these documents will not be included.
--
`null_value`::
+
--
When the `null_value` parameter is set to `true`, the missing
filter will include documents where the field contains a `null` value, ie:
[source,js]
--------------------------------------------------
{ "user": null }
{ "user": [null] }
{ "user": ["jane",null] } <1>
--------------------------------------------------
<1> Matches because the field contains a `null` value, even though it also contains a non-`null` value.
When set to `false` (the default), these documents will not be included.
--
NOTE: Either `existence` or `null_value` or both must be set to `true`.
[float]
==== Caching
The result of the filter is always cached.
|