FROM, KEEP and LIMIT
10 min · 2 ejercicio(s)
An ES|QL query is a pipeline. It starts with a source command that produces a table, followed by processing commands separated by the pipe character |. Each command receives the table of the previous one and returns a new table.
FROM lab-auth
| KEEP @timestamp, user.name, source.ip, event.outcome
| LIMIT 10| Command | Purpose |
|---|---|
FROM index |
Reads documents from one or more indices (FROM lab-auth, lab-web or FROM lab-*) |
KEEP a, b |
Keeps only the listed columns, in this order (wildcards allowed: KEEP user.*) |
DROP a |
Removes columns |
RENAME a AS b |
Renames a column |
LIMIT n |
Returns at most n rows (default 1,000) |
Unlike KQL, the result of ES|QL is always a table with columns and rows, not a list of documents. That's why ES|QL can also calculate and aggregate.
Counting rows
The quickest way to count is STATS, which you will learn in detail in the next module:
FROM lab-web
| STATS requests = COUNT(*)🔎 Profundiza: funciones, errores habituales y práctica
Source commands
| Command | Purpose |
|---|---|
FROM |
read documents from indices, aliases or data streams; supports wildcards and METADATA _id, _index |
ROW |
create a single row with literal values, great for testing functions: ROW ip = TO_IP("10.1.2.3") | EVAL internal = CIDR_MATCH(ip, "10.0.0.0/8") |
SHOW INFO |
version information of the cluster |
Shaping the table
KEEPdefines the order of columns and supports wildcards:KEEP @timestamp, user.*.DROPremoves columns,RENAME old AS newrenames them.- Columns that exist in one index but not another are
nullin rows from the other index.
Default limit
Without LIMIT ES|QL returns 1,000 rows. The maximum per query is 10,000 (configurable on the cluster). Aggregations with STATS work on all matching documents, only the output is limited.
Using it in Kibana
In Discover switch the query language to ES|QL. A STATS … BY with a date bucket draws a chart automatically, and you can save the query as a visualisation on a dashboard.