## ENRICH

The `ENRICH` command in ES|QL allows you to add data from existing indices as new columns using an enrich policy. This can be particularly useful when you need to supplement your query data with additional information stored in other indices. 

Before you can use `ENRICH`, you need to create and execute an enrich policy. Refer to the [Data enrichment](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest-enriching-data.html) documentation for information about setting up a policy.

Please note that in case of name collisions, the newly created columns will override existing columns.

### Syntax

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

#### Parameters

- `policy`: The name of the enrich policy. You need to create and execute the enrich policy first.
- `match_field`: The match field. ENRICH uses its value to look for records in the enrich index. If not specified, the match will be performed on the column with the same name as the match_field defined in the enrich policy.
- `fieldX`: The enrich fields from the enrich index that are added to the result as new columns. If a column with the same name as the enrich field already exists, the existing column will be replaced by the new column. If not specified, each of the enrich fields defined in the policy is added.
- `new_nameX`: Enables you to change the name of the column that’s added for each of the enrich fields. Defaults to the enrich field name.

### Examples

The following examples showcase different usages of the `ENRICH` command:

1. Using the `languages_policy` enrich policy to add a new column for each enrich field defined in the policy. The match is performed using the `match_field` defined in the enrich policy and requires that the input table has a column with the same name (`language_code` in this example). 

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

2. Using 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
```

3. Explicitly selecting the enrich fields that are added using `WITH <field1>, <field2>, ...`:

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

4. Renaming the columns that are added using `WITH new_name=<field1>`:

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