## ENRICH

The `ENRICH` command allows you to add data from existing indices as new columns using an enrich policy.

## Syntax

`ENRICH policy [ON match_field] [WITH [new_name1 = ]field1, [new_name2 = ]field2, ...]`

### Parameters

#### `policy`

The name of the enrich policy. You must create and execute the enrich policy before using it.

#### `mode`

(Optional) The mode of the enrich command in cross-cluster queries. Refer to enrich across clusters for more details.

#### `match_field`

(Optional) The field used to match records in the enrich index. If not specified, the match is performed on the column with the same name as the `match_field` defined in the enrich policy.

#### `fieldX`

(Optional) The enrich fields from the enrich index to be added as new columns. If a column with the same name as the enrich field already exists, it will be replaced. If not specified, all enrich fields defined in the policy are added. Columns with the same name as the enrich fields will be dropped unless renamed.

#### `new_nameX`

(Optional) Allows you to rename the columns added for each enrich field. Defaults to the enrich field name. If a column with the same name as the new name already exists, it will be discarded. If a name (new or original) occurs more than once, only the rightmost duplicate creates a column.

## Examples

Basic usage

Add a new column for each enrich field defined in the `languages_policy` enrich policy. The match is performed using the `match_field` defined in the policy, requiring the input table to have a column with the same name (`language_code` in this case).

```esql
ROW language_code = "1"
| ENRICH languages_policy
```

Using a different match field

Use a column with a different name than the `match_field` defined in the policy as the match field.

```esql
ROW a = "1"
| ENRICH languages_policy ON a
```

Selecting specific enrich fields

Explicitly select the enrich fields to be added as columns.

```esql
ROW a = "1"
| ENRICH languages_policy ON a WITH language_name
```

Renaming added columns

Rename the columns added using the `WITH` clause.

```esql
ROW a = "1"
| ENRICH languages_policy ON a WITH name = language_name
```

In case of name collisions, the newly created columns will override existing columns.

## Limitations

- The `ENRICH` command requires an existing enrich policy to be created and executed beforehand.
- The `match_field` in the `ENRICH` command must match the type defined in the enrich policy. For example:
  - A `geo_match` policy requires a `match_field` of type `geo_point` or `geo_shape`.
  - A `range` policy requires a `match_field` of type `integer`, `long`, `date`, or `ip`, depending on the range field type in the enrich index.
  - For `range` policies, if the `match_field` is of type `KEYWORD`, field values are parsed during query execution. If parsing fails, the output values for that row are set to `null`, and a warning is produced.
- The `geo_match` enrich policy type only supports the `intersects` spatial relation.
