File: range-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 (105 lines) | stat: -rw-r--r-- 3,436 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
[[query-dsl-range-filter]]
=== Range Filter

Filters documents with fields that have terms within a certain range.
Similar to <<query-dsl-range-query,range
query>>, except that it acts as a filter. Can be placed within queries
that accept a filter.

[source,js]
--------------------------------------------------
{
    "constant_score" : {
        "filter" : {
            "range" : {
                "age" : {
                    "gte": 10,
                    "lte": 20
                }
            }
        }
    }
}
--------------------------------------------------

The `range` filter accepts the following parameters:

[horizontal]
`gte`::     Greater-than or equal to
`gt`::      Greater-than
`lte`::     Less-than or equal to
`lt`::      Less-than

[float]
==== Date options

When applied on `date` fields the `range` filter accepts also a `time_zone` parameter.
The `time_zone` parameter will be applied to your input lower and upper bounds and will
move them to UTC time based date:

[source,js]
--------------------------------------------------
{
    "constant_score": {
        "filter": {
            "range" : {
                "born" : {
                    "gte": "2012-01-01",
                    "lte": "now",
                    "time_zone": "+1:00"
                }
            }
        }
    }
}
--------------------------------------------------

In the above example, `gte` will be actually moved to `2011-12-31T23:00:00` UTC date.

NOTE: if you give a date with a timezone explicitly defined and use the `time_zone` parameter, `time_zone` will be
ignored. For example, setting `gte` to `2012-01-01T00:00:00+01:00` with `"time_zone":"+10:00"` will still use `+01:00` time zone.

When applied on `date` fields the `range` filter accepts also a `format` parameter.
The `format` parameter will help support another date format than the one defined in mapping:

[source,js]
--------------------------------------------------
{
    "constant_score": {
        "filter": {
            "range" : {
                "born" : {
                    "gte": "01/01/2012",
                    "lte": "2013",
                    "format": "dd/MM/yyyy||yyyy"
                }
            }
        }
    }
}
--------------------------------------------------

[float]
==== Execution

The `execution` option controls how the range filter internally executes. The `execution` option accepts the following values:

[horizontal]
`index`::       Uses the field's inverted index in order to determine whether documents fall within the specified range.
`fielddata`::   Uses fielddata in order to determine whether documents fall within the specified range.

In general for small ranges the `index` execution is faster and for longer ranges the `fielddata` execution is faster.

The `fielddata` execution, as the name suggests, uses field data and therefore
requires more memory, so make sure you have sufficient memory on your nodes in
order to use this execution mode. It usually makes sense to use it on fields
you're already aggregating or sorting by.

[float]
==== Caching

The result of the filter is only automatically cached by default if the `execution` is set to `index`. The
`_cache` can be set to `false` to turn it off.

If the `now` date math expression is used without rounding then a range filter will never be cached even if `_cache` is
set to `true`. Also any filter that wraps this filter will never be cached.