ES|QL EVAL command
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. Serverless interfaces and procedures might differ from classic Elastic Stack deployments. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless
Generally available
Stack
Generally available
The EVAL processing command enables you to append new columns with calculated
values.
EVAL [column1 =] value1[, ..., [columnN =] valueN]
columnX- The column name. If a column with the same name already exists, the existing column is dropped. If a column name is used more than once, only the rightmost duplicate creates a column.
valueX- The value for the column. Can be a literal, an expression, or a function. Can use columns defined left of this one.
The EVAL processing command enables you to append new columns with calculated
values. EVAL supports various functions for calculating values. Refer to
Functions for more information.
ES|QL respects runtime fields defined in the index mapping, but does not support defining new runtime fields at search time. Use EVAL to create computed columns at query time instead.
The following examples show common EVAL patterns.
FROM employees
| SORT emp_no
| KEEP first_name, last_name, height
| EVAL height_feet = height * 3.281, height_cm = height * 100
| first_name:keyword | last_name:keyword | height:double | height_feet:double | height_cm:double |
|---|---|---|---|---|
| Georgi | Facello | 2.03 | 6.66043 | 202.99999999999997 |
| Bezalel | Simmel | 2.08 | 6.82448 | 208.0 |
| Parto | Bamford | 1.83 | 6.004230000000001 | 183.0 |
If the specified column already exists, the existing column will be dropped, and the new column will be appended to the table:
FROM employees
| SORT emp_no
| KEEP first_name, last_name, height
| EVAL height = height * 3.281
| first_name:keyword | last_name:keyword | height:double |
|---|---|---|
| Georgi | Facello | 6.66043 |
| Bezalel | Simmel | 6.82448 |
| Parto | Bamford | 6.004230000000001 |
Specifying the output column name is optional. If not specified, the new column
name is equal to the expression. The following query adds a column named
height*3.281:
FROM employees
| SORT emp_no
| KEEP first_name, last_name, height
| EVAL height * 3.281
| first_name:keyword | last_name:keyword | height:double | height * 3.281:double |
|---|---|---|---|
| Georgi | Facello | 2.03 | 6.66043 |
| Bezalel | Simmel | 2.08 | 6.82448 |
| Parto | Bamford | 1.83 | 6.004230000000001 |
Because this name contains special characters, it needs to be quoted with backticks (```) when using it in subsequent commands:
FROM employees
| EVAL height * 3.281
| STATS avg_height_feet = AVG(`height * 3.281`)
| avg_height_feet:double |
|---|
| 5.801464200000001 |