Ship Logs with Filebeat and Logstash, Hands-On
In lesson 16 a shop-logs-* index appeared on its own. One day it will not: Kibana shows nothing, or each log line is one unsearchable string. To fix that, you need to know what carries each line and where it can get stuck. This lesson walks through the lab's Filebeat and Logstash configuration, adds a filter, and checks each hop.
The couriers and the sorting office
Filebeat is small on purpose. In production one copy runs on every machine, so it does as little as possible: it reads new lines, ships them, and remembers how far it got. Logstash runs centrally, so it can afford the heavier work of parsing, cleaning and routing every event.
The flowchart follows one line through the lab. Every decision sits in Logstash; Filebeat only moves the line and keeps its place.
Filebeat: read the file, ship to port 5044
Here is filebeat/filebeat.yml from course-labs/open-source-observability-stack/05-elk, without its comments. One input says what to read, and one output says where to send it:
filebeat.inputs:
- type: filestream
id: shop-demo-log
paths:
- /var/log/shop-demo/*.log
output.logstash:
hosts: ["logstash:5044"]
filestream is Filebeat's input for log files. Every filestream input needs a unique id, because Filebeat stores each file's read position under it and refuses to start two inputs with the same id. paths takes wildcard patterns, and it is a path inside the Filebeat container, where the shop-logs volume is mounted read-only. Filebeat checks for new matching files every 10 seconds by default.
That read position is the offset: how many bytes of the file Filebeat has shipped. Filebeat saves it in its registry only once Logstash confirms a batch. After a restart, it resends anything sent but not confirmed, so delivery to Logstash is at least once: a line may arrive twice, but a Filebeat restart loses none.
output.logstash sends events to the logstash service on the obs-lab network, port 5044, using the beats protocol. Filebeat allows only one output, and it does not parse anything here: each line travels as plain text in a field called message.
The Logstash pipeline: input, filter, output
Logstash joins every file in its pipeline folder into one pipeline. In the lab that is just logstash/pipeline/shop-logs.conf, shown here without its comments. Each event passes through the filters from top to bottom.
input {
beats {
port => 5044
}
}
filter {
json {
source => "message"
remove_field => ["message"]
}
if [route] == "/" and [status] == 200 {
drop { }
}
date {
match => ["timestamp", "ISO8601"]
remove_field => ["timestamp"]
}
mutate {
rename => { "msg" => "message" }
remove_field => ["agent", "ecs", "input", "event"]
}
}
output {
elasticsearch {
hosts => ["http://elasticsearch:9200"]
index => "shop-logs-%{+YYYY.MM.dd}"
}
}
The beats input listens on port 5044 and turns each line into an event, Logstash's word for one record and its fields. The json filter parses the text in message into top-level fields such as level, route and status. Its remove_field runs only when parsing worked, so a line that is not JSON keeps its text.
The if block is a conditional, a test on the event's fields. It drops successful visits to /, the app's description page and about one loadgen request in ten. A dropped event never reaches Elasticsearch; failed visits to / are kept.
The date filter reads the app's timestamp and writes it to @timestamp, the field Elasticsearch and Kibana treat as the event's time. Without it, @timestamp would be the moment Filebeat read the line: milliseconds late normally, hours late after an outage.
mutate renames shop-demo's msg to message, the name most tools expect, and removes noise. agent, ecs and input are Filebeat's bookkeeping. event holds event.original, a copy of the raw line that Logstash keeps in its ECS mode, Elastic's standard field naming, which is on by default; without this, every line would be stored twice.
One index per day
In shop-logs-%{+YYYY.MM.dd}, the %{+…} part is filled in for each event from its @timestamp, as a date in UTC. So each event lands in the index for its own day: a line written at 23:59 UTC that arrives after midnight still goes into yesterday's index.
As lesson 16 showed, deleting a whole index is one cheap request, so keeping 14 days means deleting the oldest index each day; in production, index lifecycle management can do it for you. %{+…} is the older Joda-Time syntax, deprecated but still supported. The newer %{{yyyy.MM.dd}} needs a lowercase year, because in Java time YYYY is the year of the week, which can differ from the calendar year in late December.
Check that data is flowing
Check one hop at a time, from the 05-elk folder. First load the new pipeline: Logstash reads its pipeline files only when it starts, so restart it, then search its log for two start-up lines:
docker compose restart logstash
docker compose logs logstash | grep -E "Starting input listener|Pipelines running"
Within a minute you should see Starting input listener with the address 0.0.0.0:5044, then Pipelines running with a count of 1. If neither appears, read docker compose logs logstash without the grep: a typo in the file shows up there as an error naming the line and column. An info line saying ECS compatibility is enabled but `target` option was not specified is harmless here.
Then check that Filebeat has reconnected. While Logstash restarts, Filebeat logs Failed to connect to backoff(async(tcp://logstash:5044)) and keeps retrying, which is normal for a minute or so:
docker compose logs filebeat | grep "Connection to"
The newest line should read Connection to backoff(async(tcp://logstash:5044)) established. Every 30 seconds Filebeat also logs Non-zero metrics in the last 30s, whose acked count under libbeat.output.events is the number of lines Logstash confirmed. The last hop, Elasticsearch, is the try-it below.
Common problems: path, parse failures, time zones
Wrong file path. A path that matches no file is not an error: Filebeat simply keeps looking. A common slip is writing the path on your laptop instead of the one inside the container. See what Filebeat sees with docker compose exec filebeat ls -l /var/log/shop-demo/; you should see shop-demo.log.
JSON parse failures. A line that is not valid JSON, such as a stray print() or a stack trace, is stored anyway. It keeps its raw text in message, gets the tag _jsonparsefailure, and has Filebeat's read time as @timestamp. It is searchable as text, but it has no fields.
Time zones. shop-demo writes UTC with a Z at the end, so the date filter reads the zone from the text. A time written without a zone is read in Logstash's own time zone, which shifts it by hours; set the filter's timezone option for such logs. Index names also follow UTC, so in India today's index starts at 05:30.
Check yourself
Logstash was down for two hours, and Filebeat has just caught up. Without the date filter, what would look wrong in those documents?
Their @timestamp would be the catch-up time, when Filebeat read them, so the two hours would show as a gap followed by a spike. The date filter uses the time the app wrote into each line.
A teammate in India looks for shop-logs-2026.11.28 at 03:00 local time on 28 November and cannot find it. Why?
It is still 21:30 on 27 November in UTC, and index names use the UTC day of @timestamp. New lines still go to shop-logs-2026.11.27 until 05:30 local time.
Filebeat restarts in the middle of a batch. Are any lines lost or sent twice?
None are lost, but some may arrive twice. Filebeat saves its offset only after Logstash confirms a batch, so it resends anything sent but not confirmed: delivery is at least once.