Iniciar sesión

What is ES|QL?

10 min · 2 ejercicio(s)

ES|QL (Elasticsearch Query Language) is Elastic's piped query language for searching, filtering, aggregating and transforming data. You write a query as a chain of commands, each one separated by a pipe |, and Elasticsearch returns a table:

FROM lab-auth
| WHERE event.outcome == "failure"
| STATS failures = COUNT(*) BY user.name
| SORT failures DESC
| LIMIT 5

Read it from top to bottom like a recipe: take the authentication events, keep the failures, count them per user, sort, show the top five.

Why a new language?

KQL can only filter. To count, group or calculate, you used to build visualizations or write JSON aggregations in Query DSL. ES|QL does all of it in one readable query. It runs on its own compute engine inside Elasticsearch that processes data in parallel, column by column, so even heavy aggregations come back fast. ES|QL is generally available since Elasticsearch 8.14.

Where you use ES|QL

Place What you do there
Discover (language switch ES|QL) Explore data, see the result as a table and a chart
Dashboards Panels based on an ES|QL query
Alerting / Elastic Security ES|QL rules that alert on aggregated results, e.g. "more than 50 failures per user in 5 minutes"
Timeline in Elastic Security Hunt in the ES|QL tab
POST _query API Run queries from scripts and applications

The building blocks

Kind Commands Purpose
Source commands FROM, ROW, SHOW Produce the first table, e.g. from an index
Processing commands WHERE, KEEP, SORT, STATS, EVAL, DISSECT, GROK, LOOKUP JOIN, … Take a table, return a new one
Functions and operators COUNT(), ROUND(), TO_LOWER(), ==, LIKE, … Used inside commands

Every query starts with exactly one source command. Commands are written in upper case by convention, but ES|QL doesn't care.

KQL, ES|QL or EQL?

Question Language
"Show me the events where …" KQL (or ES|QL WHERE)
"How many … per …?", "Top 10 …", "first seen / last seen" ES|QL
"A happened, then B on the same host" EQL

Your lab

The exercises run against the same Kestrel Logistics indices as the KQL track: lab-auth, lab-endpoint, lab-web and the lookup index lab-threatintel. In ES|QL you choose the index yourself in FROM. Results are limited to 1,000 rows unless you LIMIT them, the lab shows the first 500.

Tip: Run a query with Ctrl + Enter (or ⌘ + Enter on a Mac).

🔎 Profundiza: funciones, errores habituales y práctica

How ES|QL runs

ES|QL is not translated into Query DSL like KQL. Elasticsearch parses the query, plans it and runs it on a dedicated compute engine that works on blocks of column values and spreads the work over all shards and CPU cores. Filters at the start of the query (FROM … | WHERE …) are pushed down to the index, so they use the inverted index just like a normal search.

Results are tables

  • Every command receives a table and returns a table.
  • Column names are field names (user.name) or names you assign (failures = COUNT(*)).
  • The result has a default limit of 1,000 rows. A query without LIMIT gets an implicit one, so "all rows" is never really all rows on big data: aggregate instead.

ES|QL vs. SQL

Elasticsearch also has a SQL interface. ES|QL looks similar but reads top to bottom (FROM first, then filters, then aggregation), every step can use the result of the previous one, and it supports security-specific commands like DISSECT, GROK and LOOKUP JOIN. For new work Elastic recommends ES|QL.

Time in Kibana

In Discover the time picker filters ES|QL queries on @timestamp, just like KQL. The Querynaut lab applies no time filter: you always see the whole week of data.

Ejercicios prácticos de esta lección

Resuelve estos ejercicios con una consulta en el laboratorio Elasticsearch real. Inicia sesión gratis para acceder al laboratorio, las pistas y la corrección automática.

  1. 1. Your first pipeline

    In the KQL track you filtered the failed logons. Now count them with ES|QL: how many events in lab-auth have event.outcome failure?

  2. 2. Something KQL can't do

    Which service (service.name) has the most logons in lab-auth?