ES|QL MV_IN_RANGE function
Checks whether a multivalue field has any value within a range.
field- Multivalue expression to test. If null or empty, the function returns
false. lower- Lower bound, of the same type as
field. If null or multivalued, the function returnsfalse. upper- Upper bound, of the same type as
field. If null or multivalued, the function returnsfalse. options-
(Optional) Range boundary options.
Returns true if at least one value of field is within the range [lower, upper], using the natural order of the type. A null or empty field returns false, as does a null bound. Both bounds are inclusive by default; set include_lower or include_upper to false in the optional options map to make either bound exclusive, covering all four interval forms. Works on any ordered type: numbers, dates, IPs, versions, and strings (compared by their UTF-8 bytes).
| field | lower | upper | options | result |
|---|---|---|---|---|
| date | date | date | named parameters | boolean |
| date | date | date | boolean | |
| date_nanos | date_nanos | date_nanos | boolean | |
| double | double | double | named parameters | boolean |
| double | double | double | boolean | |
| integer | integer | integer | named parameters | boolean |
| integer | integer | integer | boolean | |
| ip | ip | ip | boolean | |
| keyword | keyword | keyword | named parameters | boolean |
| keyword | keyword | keyword | boolean | |
| keyword | keyword | text | boolean | |
| keyword | text | keyword | boolean | |
| keyword | text | text | boolean | |
| long | long | long | named parameters | boolean |
| long | long | long | boolean | |
| text | keyword | keyword | boolean | |
| text | keyword | text | boolean | |
| text | text | keyword | boolean | |
| text | text | text | boolean | |
| unsigned_long | unsigned_long | unsigned_long | boolean | |
| version | version | version | boolean |
include_lower- (boolean) Whether the lower bound is inclusive. Defaults to
true;falsemakes it exclusive (value > lower). include_upper-
(boolean) Whether the upper bound is inclusive. Defaults to
true;falsemakes it exclusive (value < upper).
ROW values = [1, 5, 10]
| EVAL in_range = mv_in_range(values, 4, 6)
| values:integer | in_range:boolean |
|---|---|
| [1, 5, 10] | true |
Neither 0 nor 100 is within [40, 60], so the result is false.
ROW values = [0, 100]
| EVAL in_range = mv_in_range(values, 40, 60)
| values:integer | in_range:boolean |
|---|---|
| [0, 100] | false |
Strings are compared by their UTF-8 bytes:
ROW words = ["apple", "cherry"]
| EVAL in_range = mv_in_range(words, "banana", "date")
| words:keyword | in_range:boolean |
|---|---|
| [apple, cherry] | true |
A half-open range [4, 6): 6 sits on the excluded upper bound, so it does not match.
ROW values = [3, 6]
| EVAL in_range = mv_in_range(values, 4, 6, {"include_upper": false})
| values:integer | in_range:boolean |
|---|---|
| [3, 6] | false |
An open range (4, 6): values equal to either bound are excluded.
ROW values = [4, 6]
| EVAL in_range = mv_in_range(values, 4, 6, {"include_lower": false, "include_upper": false})
| values:integer | in_range:boolean |
|---|---|
| [4, 6] | false |