Practice: shaping results
12 min · 2 ejercicio(s)
Cheat sheet
FROM lab-auth // source
| WHERE service.name == "rdp" // filter rows
| SORT @timestamp DESC // order
| KEEP @timestamp, user.name, host.name // choose columns
| LIMIT 20 // cap the result| Command | Purpose | Watch out |
|---|---|---|
FROM |
Index or pattern, e.g. lab-* |
Wildcards combine indices with different fields |
WHERE |
Filter with ==, !=, <, AND, OR, NOT |
Strings use double quotes |
SORT |
Order, ASC/DESC, NULLS LAST |
Sort before LIMIT |
KEEP / DROP |
Choose or remove columns | Wildcards work: KEEP host.* |
RENAME |
RENAME source.ip AS ip |
|
LIMIT |
Max rows | Default limit is 1000 rows |
Order matters
Each command works on the output of the previous one. LIMIT 1 | SORT bytes DESC takes any row and then sorts one row. SORT bytes DESC | LIMIT 1 returns the largest. Read your query top-down and ask "what does the table look like now?".
NULL values
Rows without a field have null there. WHERE source.bytes IS NOT NULL removes them before sorting, otherwise they may appear first or last depending on NULLS FIRST/LAST.