﻿---
title: ES|QL MV_IN_RANGE function
description: 
url: https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/query-languages/esql/functions-operators/mv-functions/mv_in_range
products:
  - Elasticsearch
---

# ES|QL MV_IN_RANGE function
<applies-to>
  - Elastic Stack: Planned
</applies-to>

Checks whether a multivalue field has any value within a range.

## Syntax

![Embedded](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/query-languages/esql/images/generated/x-pack-esql/functions/mv_in_range.svg)


## Parameters

<definitions>
  <definition term="field">
    Multivalue expression to test. If null or empty, the function returns `false`.
  </definition>
  <definition term="lower">
    Lower bound, of the same type as `field`. If null or multivalued, the function returns `false`.
  </definition>
  <definition term="upper">
    Upper bound, of the same type as `field`. If null or multivalued, the function returns `false`.
  </definition>
  <definition term="options">
    (Optional) Range boundary options.
  </definition>
</definitions>


## Description

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).

## Supported types


| 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 |


### Supported function named parameters

<definitions>
  <definition term="include_lower">
    (boolean) Whether the lower bound is inclusive. Defaults to `true`; `false` makes it exclusive (`value > lower`).
  </definition>
  <definition term="include_upper">
    (boolean) Whether the upper bound is inclusive. Defaults to `true`; `false` makes it exclusive (`value < upper`).
  </definition>
</definitions>


## Examples

```esql
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`.
```esql
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:
```esql
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.
```esql
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.
```esql
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            |