Logstash filters transform raw log lines into structured documents — extracting fields, normalizing types, enriching with geographic or threat data, and dropping useless events. This article walks through the filter plugins that handle 80% of real pipelines: grok, dissect, mutate, date, geoip, and drop, with conditional logic that keeps the pipeline maintainable. Audience is operators authoring or debugging Logstash filter configs.
How to verify
Test a filter config without touching production:
sudo -u logstash /usr/share/logstash/bin/logstash \
-f /etc/logstash/conf.d/test.conf --config.test_and_exit
echo '{"message":"127.0.0.1 - - [01/Jan/2026:00:00:00 +0000] \"GET / HTTP/1.1\" 200 612"}' | \
sudo -u logstash /usr/share/logstash/bin/logstash \
-f /etc/logstash/conf.d/test.conf --path.data /tmp/ls-test
curl -s 'http://logstash:9600/_node/stats/pipelines/main?pretty' | jq '.pipelines.main.plugins.filters'
A passing config returns “Config Validation Result: OK”; the sample run emits a parsed JSON document with extracted fields.
What’s happening
Logstash pipelines have three stages: input → filter → output. The filter block is a sequence of plugin invocations executed in order on each event. Filters are not transactional — a failure in one plugin doesn’t roll back earlier work, it just leaves a _grokparsefailure tag or similar.
The two main parsers:
grok— regex-based pattern matcher with a library of named patterns (%{COMMONAPACHELOG},%{IPORHOST}). Flexible but slow on complex patterns; pinning the pattern with anchors (^,$) and avoiding backtracking matters.dissect— split by delimiters, no regex. Faster than grok but only works when the format is rigidly structured.
Use dissect first when the log format is column-delimited (access.log, CSV). Fall back to grok when you have variable elements (timestamps in multiple formats, optional fields).
mutate is the swiss army knife: convert, rename, replace, remove_field, gsub, add_tag. date parses timestamps into the canonical @timestamp field. geoip enriches IPs with country/city/coordinates from MaxMind DBs.
Conditionals (if [field] == "value" { ... } else { ... }) let you branch — apply different parsers per service, drop noisy paths, or route to different outputs.
The procedure
1. Pipeline structure. A typical config in /etc/logstash/conf.d/10-nginx.conf:
input {
beats { port => 5044 }
}
filter {
if [event][module] == "nginx" {
# Parse nginx combined log format
grok {
match => {
"message" => '%{IPORHOST:[source][address]} - %{DATA:[user][name]} \[%{HTTPDATE:[nginx][access][time]}\] "%{WORD:[http][request][method]} %{DATA:[url][original]} HTTP/%{NUMBER:[http][version]}" %{NUMBER:[http][response][status_code]:int} %{NUMBER:[http][response][body][bytes]:int} "%{DATA:[http][request][referrer]}" "%{DATA:[user_agent][original]}"'
}
tag_on_failure => ["_grokparsefailure_nginx"]
}
# Parse timestamp into @timestamp
date {
match => ["[nginx][access][time]", "dd/MMM/yyyy:HH:mm:ss Z"]
target => "@timestamp"
remove_field => ["[nginx][access][time]"]
}
# Enrich client IP
geoip {
source => "[source][address]"
target => "[source][geo]"
}
# Drop healthcheck noise
if [url][original] =~ /^\/healthz/ {
drop {}
}
# Type coercion
mutate {
convert => {
"[http][response][status_code]" => "integer"
"[http][response][body][bytes]" => "integer"
}
remove_field => ["message"]
}
}
}
output {
elasticsearch {
hosts => ["https://es:9200"]
user => "logstash_writer"
password => "${ES_PASS}"
index => "logs-nginx-%{+YYYY.MM.dd}"
}
}
2. Use dissect for performance. If your log has a strict format:
filter {
dissect {
mapping => {
"message" => '%{ts} %{+ts} %{level} %{logger} - %{msg}'
}
}
}
Dissect runs 3-10x faster than equivalent grok on column-delimited data.
3. Handle multiline at the filter (not just at Filebeat). Java stack traces:
filter {
multiline {
pattern => "^\s"
what => "previous"
negate => false
}
}
Prefer multiline at the source (Filebeat input parser) when possible — pushing multi-event reconstruction into Logstash is more fragile across Logstash worker restarts.
4. Conditional output routing:
output {
if [event][module] == "nginx" {
elasticsearch { ... index => "logs-nginx-%{+YYYY.MM.dd}" }
} else if [event][module] == "mysql" {
elasticsearch { ... index => "logs-mysql-%{+YYYY.MM.dd}" }
} else {
elasticsearch { ... index => "logs-other-%{+YYYY.MM.dd}" }
}
}
5. Test grok patterns with the debugger. Kibana ships a Grok Debugger under Dev Tools — paste a sample line and pattern, get a parsed result without restarting Logstash.
6. Drop noise before enrichment. Place drop {} early so you don’t pay geoip lookup cost for events you’ll throw away:
filter {
if [user_agent][original] =~ /(googlebot|bingbot|UptimeRobot)/ {
drop {}
}
geoip { source => "[source][address]" }
}
Common pitfalls
_grokparsefailureflood. A single unmatched pattern tags every event. Add a fallback grok or usedissect+if !_grokparsefailure { ... }guards.- Regex backtracking. Patterns like
.*inside grok cause exponential matching time. Use[^"]*or specific patterns; profile with the pipelines stats API. - MaxMind DB licensing. Free GeoLite2 DBs require an account since 2020. Set
databasepath explicitly and refresh weekly. - Field naming inconsistency. ECS (Elastic Common Schema) uses
[source][address], notclientip. Standardize on ECS or you’ll fight Kibana dashboards forever. - Pipeline reloads aren’t always safe.
config.reload.automatic: trueworks for most plugins but some (especiallyjdbc_static) leak resources across reloads. Restart on schema changes.
In the engagements we run, Logstash filter pipelines are where most of the operational work lives — fields drift as services evolve, new modules need parsing, and old _grokparsefailure tags hide rotting parsers. We treat the filter configs as code: source control, code review, and a staging pipeline before production deploys. See /en/services/managed-operations/ for how we operate the full ELK pipeline.