Practice: computed columns and parsing
15 min · 2 ejercicio(s)
Cheat sheet
| Task | ES|QL |
|---|---|
| New column | EVAL mb = source.bytes / 1048576.0 |
| Round | ROUND(x, 2) |
| Text case | TO_LOWER(file.extension) |
| Join strings | CONCAT(user.name, "@", host.name) |
| Prefix / suffix | STARTS_WITH(host.name, "srv-"), ENDS_WITH(...) |
| Pattern | process.command_line LIKE "*-enc*", RLIKE for regex |
| Conditional | CASE(cond1, v1, cond2, v2, default) |
| Split text | DISSECT field "%{a} %{b}" |
| Regex extract | GROK field "%{IP:ip} %{WORD:verb}" |
Integer division
source.bytes / 1048576 with two integers is an integer division and drops the decimals. Divide by 1048576.0 (a double) to keep them.
DISSECT or GROK?
- DISSECT splits on fixed delimiters. Fast, simple, perfect for structured strings like user agents (
sqlmap/%{version}#%{channel}). - GROK uses regular expressions. Use it when the format varies or you need types (
%{NUMBER:n:int}).
CASE for triage
CASE turns raw values into labels you can count: status codes into ok / client_error / server_error, hours into day / night, byte counts into small / large. The first matching condition wins, so order from most to least specific.