File: exists-filter.asciidoc

package info (click to toggle)
elasticsearch 1.6.2%2Bdfsg-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 59,348 kB
  • sloc: java: 461,436; xml: 1,913; python: 1,402; sh: 1,183; ruby: 618; perl: 172; makefile: 46
file content (81 lines) | stat: -rw-r--r-- 2,273 bytes parent folder | download
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
[[query-dsl-exists-filter]]
=== Exists Filter

Returns documents that have at least one non-`null` value in the original field:

[source,js]
--------------------------------------------------
{
    "constant_score" : {
        "filter" : {
            "exists" : { "field" : "user" }
        }
    }
}
--------------------------------------------------

For instance, these documents would all 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> At least one non-`null` value is required.

These documents would *not* match the above filter:

[source,js]
--------------------------------------------------
{ "user": null }
{ "user": [] } <1>
{ "user": [null] } <2>
{ "foo":  "bar" } <3>
--------------------------------------------------
<1> This field has no values.
<2> At least one non-`null` value is required.
<3> The `user` field is missing completely.

[float]
==== `null_value` mapping

If the field mapping includes the `null_value` setting (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
following docs would match the `exists` 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 not match the `exists` filter:

[source,js]
--------------------------------------------------
{ "user": [] }
{ "foo": "bar" }
--------------------------------------------------


[float]
==== Caching

The result of the filter is always cached.