Taming Noisy Logs with Filebeat Multiline Support – A Practical Guide
Filebeat’s multiline feature lets you aggregate multi‑line logs into single events, cutting noise and storage costs. Follow this practical guide to configure, test, and validate the feature safely.
18 Jan 2026, 22:44 UTC

Why Multiline Logs Are a Pain Point
When a single logical event – like a Java stack trace or a JSON payload – spills over several physical lines, Filebeat treats each line as a separate event. In Elasticsearch this results in fragmented documents, wasted storage, and noisy dashboards. Operators often end up writing custom scripts to stitch lines together before shipping, which is error‑prone and hard to maintain.
Filebeat’s Built‑In Multiline Feature
Starting with version 7.12, Filebeat can aggregate lines that belong together into a single event using two simple configuration options:
multiline.pattern– a regular expression that matches the beginning of a new event.multiline.negate– when set totrue, lines that do not match the pattern are appended to the previous event.
When configured correctly, this feature eliminates the need for external preprocessing, reduces ingestion overhead, and keeps your indices tidy.
Step‑by‑Step Configuration
- Create a test log file
Place the following content in/var/log/app.log(adjust path as needed):[2026-10-13 02:00:00] INFO Starting service [2026-10-13 02:00:01] ERROR NullPointerException at com.example.Main.main(Main.java:42) at java.base/java.lang.Thread.run(Thread.java:748) [2026-10-13 02:00:02] INFO Service stopped - Edit Filebeat’s configuration
Open/etc/filebeat/filebeat.ymland add the following under your input section:filebeat.inputs: - type: log enabled: true paths: - /var/log/app.log multiline.pattern: '^\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\]' multiline.negate: true multiline.match: afterExplanation: The regex matches the timestamped bracketed prefix of each new log line. Setting
negate: truetells Filebeat to append any line that doesn’t match the pattern to the previous event.match: afterensures the first matched line starts the new event. - Run Filebeat
Execute:sudo systemctl restart filebeatFilebeat must run as the
rootuser or a user with read permission on the log file. - Verify in Kibana
Open Kibana, go toDiscover, and search for the index patternfilebeat-*. You should see three documents: one for the INFO line, one for the full stack trace, and one for the final INFO line.
Trade‑Offs and Caveats
- Pattern precision matters – A regex that is too broad will merge unrelated entries, corrupting semantics. A regex that is too strict may split a single event into multiple documents.
- Potential data loss – If the first line of a batch does not match the pattern, the entire batch is discarded. Always test with representative logs before production.
- Performance impact – Aggregating lines in Filebeat reduces the number of events sent to Elasticsearch, lowering indexing load. However, complex regex evaluation can increase CPU usage on the Filebeat host.
How to Test Your Configuration
1. Run Filebeat in --configtest mode to catch syntax errors:
sudo filebeat test config
2. Use the --simulate flag to preview how logs will be grouped:
sudo filebeat --simulate -c /etc/filebeat/filebeat.yml -d '*'
3. Compare the byte size of the raw log file to the number of indexed documents. A lower event count per byte indicates successful aggregation.
Actionable Takeaway
Implementing multiline.pattern and multiline.negate in Filebeat is a low‑effort, high‑impact change that cleans up your ELK stack. Start by testing with a small sample, validate the grouping in Kibana, and then roll out to production. Remember: a precise regex, careful testing, and monitoring of ingestion metrics are key to avoiding data loss and ensuring reliable log analytics.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.