﻿---
title: ES|QL MV_UNION function
description: 
url: https://www.elastic.co/elastic/docs-builder/docs/3729/reference/query-languages/esql/functions-operators/mv-functions/mv_union
products:
  - Elasticsearch
---

# ES|QL MV_UNION function
<applies-to>
  - Elastic Cloud Serverless: Preview
  - Elastic Stack: Preview since 9.4
</applies-to>

Returns all unique values from the combined multi-value fields.

## Syntax

![Embedded](https://www.elastic.co/elastic/docs-builder/docs/3729/reference/query-languages/esql/images/generated/x-pack-esql/functions/mv_union.svg)


## Parameters

<definitions>
  <definition term="field1">
    Expression that can be null, a single value, or multiple values. Null values are treated as empty sets.
  </definition>
  <definition term="field2">
    Expression that can be null, a single value, or multiple values. Null values are treated as empty sets.
  </definition>
</definitions>


## Description

Returns all unique values from the combined input fields (set union). Null values are treated as empty sets; returns `null` only if both fields are null.

## Supported types


| field1                                                              | field2                                                              | result          |
|---------------------------------------------------------------------|---------------------------------------------------------------------|-----------------|
| boolean                                                             | boolean                                                             | boolean         |
| cartesian_point                                                     | cartesian_point                                                     | cartesian_point |
| cartesian_shape                                                     | cartesian_shape                                                     | cartesian_shape |
| date                                                                | date                                                                | date            |
| date_nanos                                                          | date_nanos                                                          | date_nanos      |
| double                                                              | double                                                              | double          |
| flattened <applies-to>Elastic Stack: Preview since 9.5</applies-to> | flattened <applies-to>Elastic Stack: Preview since 9.5</applies-to> | flattened       |
| geo_point                                                           | geo_point                                                           | geo_point       |
| geo_shape                                                           | geo_shape                                                           | geo_shape       |
| geohash                                                             | geohash                                                             | geohash         |
| geohex                                                              | geohex                                                              | geohex          |
| geotile                                                             | geotile                                                             | geotile         |
| integer                                                             | integer                                                             | integer         |
| ip                                                                  | ip                                                                  | ip              |
| keyword                                                             | keyword                                                             | keyword         |
| keyword                                                             | text                                                                | keyword         |
| long                                                                | long                                                                | long            |
| text                                                                | keyword                                                             | keyword         |
| text                                                                | text                                                                | keyword         |
| unsigned_long                                                       | unsigned_long                                                       | unsigned_long   |
| version                                                             | version                                                             | version         |


## Examples

```esql
ROW a = [1, 2, 3, 4, 5], b = [2, 3, 4, 5, 6]
| EVAL finalValue = MV_UNION(a, b)
| KEEP finalValue
```


| finalValue:integer |
|--------------------|
| [1, 2, 3, 4, 5, 6] |

```esql
ROW a = [1, 2, 3, 4, 5]::long, b = [2, 3, 4, 5, 6]::long
| EVAL finalValue = MV_UNION(a, b)
| KEEP finalValue
```


| finalValue:long    |
|--------------------|
| [1, 2, 3, 4, 5, 6] |

```esql
ROW a = [true, false], b = [false]
| EVAL finalValue = MV_UNION(a, b)
| KEEP finalValue
```


| finalValue:boolean |
|--------------------|
| [true, false]      |

```esql
ROW a = [5.2, 10.5, 1.12345], b = [10.5, 2.6928]
| EVAL finalValue = MV_UNION(a, b)
| KEEP finalValue
```


| finalValue:double            |
|------------------------------|
| [5.2, 10.5, 1.12345, 2.6928] |

```esql
ROW a = ["one", "two", "three"], b = ["two", "four"]
| EVAL finalValue = MV_UNION(a, b)
| KEEP finalValue
```


| finalValue:keyword              |
|---------------------------------|
| ["one", "two", "three", "four"] |