Build pipelines

Logstash grok and dissect examples for real log lines

Parsing is where raw text becomes useful fields. These examples cover the formats you meet most often, plus the habits that keep grok fast and debuggable.

Updated 22 November 202610 min readWritten for Logstash 9.5

A log line with each value highlighted and linked to its grok pattern such as IP, WORD and NUMBER

How grok works

Grok matches text against regular expressions that are stored as named patterns. You write %{SYNTAX:SEMANTIC}: SYNTAX is the pattern name (IP, NUMBER, TIMESTAMP_ISO8601) and SEMANTIC is the field to store the match in. Logstash bundles a large library of patterns, so most common formats need no hand-written regex at all.

Since Logstash 8.0, pipelines run in ECS compatibility mode by default (pipeline.ecs_compatibility: v8). Bundled composite patterns such as COMBINEDAPACHELOG then produce Elastic Common Schema field names, for example [source][address] rather than the old clientip. Keep that in mind when you copy older examples from the web.

Example 1: Apache and Nginx access logs

A typical combined-format line:

203.0.113.7 - - [02/Nov/2026:09:14:52 +0000] "GET /api/orders HTTP/1.1" 200 512 "-" "curl/8.5.0"

The bundled pattern handles it in one line. Follow it with a date filter so @timestamp reflects when the request happened, not when Logstash read it:

filter {
  grok {
    match => { "message" => "%{COMBINEDAPACHELOG}" }
  }
  date {
    match  => ["timestamp", "dd/MMM/yyyy:HH:mm:ss Z"]
    remove_field => ["timestamp"]
  }
}

Look at the result with stdout { codec => rubydebug } before sending anything to Elasticsearch. Field names under ECS mode include [http][request][method], [url][original] and [http][response][status_code].

Example 2: an application log line

2026-11-02 09:14:52,118 ERROR [orders-worker-3] Payment declined for order 88231
filter {
  grok {
    match => {
      "message" => "^%{TIMESTAMP_ISO8601:[log][timestamp]} %{LOGLEVEL:[log][level]} \[%{DATA:[process][thread][name]}\] %{GREEDYDATA:[log][text]}$"
    }
  }
  date {
    match => ["[log][timestamp]", "yyyy-MM-dd HH:mm:ss,SSS"]
  }
}

Three details make this pattern reliable: the ^ and $ anchors stop grok from trying the pattern at every position in the line; the square brackets around the thread name are escaped because they are regex characters; and GREEDYDATA appears only at the end, where it cannot swallow text that later patterns need.

Example 3: dissect for fixed delimiters

When fields are always separated the same way, dissect is simpler and faster than grok because it splits on literal delimiters instead of running regular expressions:

10.1.4.22 GET /cart/checkout 302 41ms
filter {
  dissect {
    mapping => { "message" => "%{[source][ip]} %{[http][request][method]} %{[url][path]} %{[http][response][status_code]} %{[event][duration_ms]}ms" }
    convert_datatype => {
      "[http][response][status_code]" => "int"
      "[event][duration_ms]"          => "int"
    }
  }
}

A good rule: use dissect for the fixed-position part of a line and grok only for the irregular remainder. Both filters can run in sequence on the same event.

Example 4: key=value data

Firewall and audit logs often look like user=alice action=login result=success src=198.51.100.20. The kv filter turns every pair into a field without any pattern:

filter {
  kv {
    source      => "message"
    target      => "[audit]"
    field_split => " "
    value_split => "="
  }
}

Setting a target keeps unknown keys from cluttering the top level of the event.

Custom patterns

Define project-specific patterns inline with pattern_definitions, then use them like the bundled ones:

grok {
  pattern_definitions => { "ORDER_ID" => "ORD-[0-9]{6}" }
  match => { "message" => "order %{ORDER_ID:[order][id]} shipped" }
}

For many patterns, put them in a directory and reference it with patterns_dir, one NAME regex pair per line.

Keeping grok fast

  • Anchor patterns with ^ and $. Unanchored patterns that fail are retried at every character offset.
  • List the most common format first when you give grok several patterns; matching stops at the first success by default (break_on_match => true).
  • Avoid GREEDYDATA and DATA in the middle of a pattern where a more specific pattern such as NOTSPACE will do.
  • Keep the default timeout_millis so a pathological line cannot stall a worker, and watch for the _groktimeout tag.

Fixing _grokparsefailure

When no pattern matches, grok adds the _grokparsefailure tag and leaves the event otherwise untouched. To find out why:

  1. Route failures to a file so they are easy to inspect: if "_grokparsefailure" in [tags] { file { path => "/tmp/grok-failures.log" } }.
  2. Paste a failing line and your pattern into the Grok Debugger in Kibana (under Dev Tools) and build the pattern up piece by piece until the mismatch appears.
  3. Check for invisible differences: tabs instead of spaces, a missing timezone, or an extra field added by a newer version of the application.

Date problems show up the same way with a _dateparsefailure tag; the format string must match the text exactly, including milliseconds and the timezone. More fixes are collected in fixing common Logstash errors, and the surrounding pipeline syntax is covered in Logstash pipeline configuration.