|) to manipulate and transform data step by step. The output of one operation becomes the input for the next, enabling complex data transformations and analysis in a single readable query.
How it works
A query is a pipeline of commands separated by the pipe character (|). Each command operates on the output of the previous one:
- Reads from
sample_data - Filters to documents from the last 24 hours
- Computes the average
durationgrouped byservice - Sorts by average duration descending
- Returns the top 10 results
Running ES|QL queries
- REST API
- Kibana
Send queries to the The response returns rows and column metadata:
_query endpoint with a Content-Type of application/json:Source commands
Source commands begin every ES|QL pipeline. They define the data to operate on.FROM
Reads documents from one or more indices or data streams. Supports wildcards and comma-separated patterns.Processing commands
Processing commands transform the data flowing through the pipeline.WHERE — filter rows
WHERE — filter rows
Keeps only rows matching the condition. Supports comparison operators, boolean logic, and functions.
STATS — aggregate data
STATS — aggregate data
Computes aggregations over rows, optionally grouped with
BY. Produces one row per group.EVAL — compute new fields
EVAL — compute new fields
Creates new columns by evaluating expressions against each row. The original row is preserved with the new field appended.
SORT — order results
SORT — order results
Sorts rows by one or more expressions.
ASC is the default; use DESC for descending order. NULLS FIRST and NULLS LAST control null ordering.LIMIT — cap row count
LIMIT — cap row count
Restricts the number of rows returned by the pipeline. Always include
LIMIT in exploratory queries to avoid retrieving millions of rows.KEEP and DROP — select columns
KEEP and DROP — select columns
KEEP retains only the specified columns. DROP removes the specified columns. Both accept wildcards.RENAME — rename a column
RENAME — rename a column
Renames one or more columns using the
AS keyword.DISSECT and GROK — parse strings
DISSECT and GROK — parse strings
Both commands extract structured fields from unstructured string fields.
- DISSECT uses a fixed-separator pattern.
- GROK uses named regular expression patterns (compatible with Logstash grok).
MV_EXPAND — expand multi-value fields
MV_EXPAND — expand multi-value fields
Converts rows with multi-value fields into multiple rows, one per value. Useful when a field contains an array of values.
ENRICH — join with enrich policies
ENRICH — join with enrich policies
Looks up fields from an enrich policy and appends them to each row. Similar to a left join against a reference dataset.
Functions
ES|QL includes a broad set of built-in functions.- Date functions
- Math functions
- String functions
| Function | Description |
|---|---|
NOW() | Current timestamp |
DATE_TRUNC(interval, date) | Truncates a date to the specified interval |
DATE_FORMAT(format, date) | Formats a date as a string |
DATE_EXTRACT(part, date) | Extracts a date component (year, month, etc.) |
