Iniciar sesión

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.

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. Classify responses

    Use CASE to put every web request into one of three classes: server_error (status ≥ 500), client_error (status ≥ 400) or ok. How many requests are client_error?

  2. 2. Most common file type

    Which file extension (lower case) appears most often in the file events of lab-endpoint?