Range2Filter Document (Data API 17.4)
Document representing a range compare with range filter, named Range2Filter.
A Range2Filter allows you to restrict a search result to hits that have fulfill the comparing method specified compare two ranges.
The first range, R1 is specified by a pair given attributes ("from_field" and "to_field" that specify a range, such as attributes "valid_from" and "valid_to".
The second range, R2 is given by a value range specified by "from_value" and "to_value".
The filter mode specifies the compare method used to compare the two ranges, including:
- overlap : R1 overlaps fully or partially with R2
- containing : R1 contains R2
- contained : R1 is contained in R2
The range filter supports several value types and relies on the natural sorting of the value type for range interpretation. Value ranges can be open ended (at one end only). It is configurable whether the lower and/or the upper bound is inclusive or exclusive.
A range 2 filter is useful for general restrictions that can be shared between searches (like a static date range) as the filter result is cached in memory. Range filters are not appropriate if the range is expected to be different for every single query (like if the user controls the date range down to the hour via some UI control). Range filters are inclusive by default.
Example: ( redemption_count BETWEEN (0,10] )
"query" : { "filtered_query": { "filter": { "range2_filter": { "from_field": "valid_from", "to_field": "valid_to", "filter_mode":"overlap", "from_value": "2007-01-01T00:00:00.000Z", "to_value": "2400-01-01T00:00:00.000Z" } }, "query": { "match_all_query": {} } } }
Property | Type | Constraints | Description |
---|---|---|---|
filter_mode
|
Enum {overlap, containing, contained} | compare mode: overlap, containing, contained (default to "overlap"). It is optional. | |
from_field
|
String | mandatory=true, nullable=false | The field name of the field that start the range 1. |
from_inclusive
|
Boolean | A flag indicating whether the lower bound of the range is inclusive (or exclusive). The default is true (which means that the given lower bound is inclusive). | |
from_value
|
Object | The configured lower bound of the filter range. The lower bound is optional. If not given, the range is open ended with respect to the lower bound. | |
to_field
|
String | mandatory=true, nullable=false | The field name of the field that end the range 1. |
to_inclusive
|
Boolean | A flag indicating whether the upper bound of the range is inclusive (or exclusive). The default is true (which means that the given upper bound is inclusive). | |
to_value
|
Object | The configured upper bound of the filter range. The upper bound is optional. If not given, the range is open ended with respect to the upper bound. |