What is Grok?
10 min · 2 ejercicio(s)
Most log sources don't send nicely named fields. They send lines of text:
Mar 11 02:14:03 srv-web-01 sshd[2211]: Failed password for root from 185.220.101.47 port 51234 ssh2For a human that line is clear. For Elasticsearch it is one long string: you can't count failures per user, you can't filter on the source IP and a detection rule can't alert on it. Grok solves this. It matches a line against a pattern built from named regular expressions and writes every match into a field of its own:
%{SYSLOGTIMESTAMP:timestamp} %{HOSTNAME:host} sshd\[%{INT:pid}\]: Failed password for %{USERNAME:user} from %{IP:ip} port %{INT:port}| Field | Value |
|---|---|
timestamp |
Mar 11 02:14:03 |
host |
srv-web-01 |
pid |
2211 |
user |
root |
ip |
185.220.101.47 |
port |
51234 |
Where you meet Grok
| Place | When it runs |
|---|---|
Ingest pipeline, grok processor |
Once, when a document is indexed. The fields are stored. |
Logstash, grok filter |
Before the data reaches Elasticsearch |
| Elastic Agent integrations | Every integration (System, Nginx, Apache, …) ships ingest pipelines full of Grok patterns |
ES|QL, GROK command |
At query time, on any string column. Nothing is stored. |
| Kibana Grok Debugger | Dev Tools → Grok Debugger, to try patterns on sample lines |
The pattern language is the same everywhere. That's why the exercises in this track ask for the pattern only, exactly as you would paste it into the Grok Debugger or a grok processor.
Your lab: the raw logs
The index lab-raw contains the Kestrel Logistics breach as it looked before any parsing: only @timestamp, the original line in message and a few fields the log shipper adds.
event.dataset |
Source | Example |
|---|---|---|
system.auth |
/var/log/auth.log (sshd) on srv-web-01 and srv-db-03 |
Accepted publickey for h.yilmaz from 10.10.5.51 … |
nginx.access |
nginx access log of the web shop | 203.0.113.66 - - [13/Mar/2026:21:07:00 +0000] "GET /products?id=12%27 HTTP/1.1" 500 … |
kestrel.shop |
The shop's application log | 2026-03-13T21:19:50.123Z WARN [admin] admin login failed … |
iptables.log |
Kernel firewall log of fw-edge-01 |
[FW-BLOCK] IN=wan0 OUT= SRC=… DST=… DPT=3389 |
Your first GROK
FROM lab-raw
| WHERE event.dataset == "kestrel.shop"
| GROK message "%{TIMESTAMP_ISO8601:ts} %{LOGLEVEL:level}"
| KEEP message, ts, level
| LIMIT 10GROK takes a string column and a pattern and adds one column per named part. The original column stays untouched.
How the exercises work
| Exercise | You write | The lab checks |
|---|---|---|
| Grok | Only the pattern, e.g. %{TIMESTAMP_ISO8601} %{LOGLEVEL:log.level} |
It runs your pattern on the raw lines in lab-raw (behind the scenes with the ES |
| DISSECT | Only the DISSECT pattern | The same, with the DISSECT command |
| Question | A short answer, e.g. a pattern name | Your answer against what Elasticsearch proves to be correct |
Test pattern shows you what your pattern extracts, so you can improve it step by step. A field your pattern doesn't fill shows up as an empty value: that's a line your pattern did not match.
🔎 Profundiza: funciones, errores habituales y práctica
Grok is regular expressions with names
Every %{NAME} is a shortcut for a regular expression that ships with Elasticsearch. %{INT} is (?:[+-]?(?:[0-9]+)), %{IP} is a long expression that matches IPv4 and IPv6. Patterns are built from other patterns: SYSLOGTIMESTAMP is %{MONTH} +%{MONTHDAY} %{TIME}. That's why Grok is easy to read but can be slow when you are careless (see module 2).
Parse once or parse at query time?
| Ingest pipeline | ES|QL GROK |
|
|---|---|---|
| Cost | Once per document, at index time | Every time the query runs |
| Fields | Stored, indexed, fast to filter and aggregate | Exist only in the query result |
| Fixing a pattern | Only affects new documents (or reindex) | Change the query, done |
| Best for | Everything you query regularly, detection rules, dashboards | Exploration, one-off investigations, sources nobody parsed yet |
A common workflow: an analyst finds an unparsed source during an incident and parses it in ES|QL. The working pattern later goes into the ingest pipeline so everybody gets the fields for free.
The message field
By convention (ECS) the original log line lives in message. Pipelines keep it after parsing, so you can always check what the parser saw. In the lab message is a keyword, which ES|QL can parse directly.