What Is the ELK Stack? Elasticsearch, Logstash, Kibana
A customer says order ord-48213 failed at 14:02. The traces from lesson 15 show which span failed, but the order's details are in shop-demo's log lines, about five a second. Scrolling docker compose logs fails long before you have thousands. The ELK stack is the classic answer: it collects log lines, files them, and finds the ones you ask for in seconds. This lesson explains each part and starts the lab.
What the ELK stack does for logs
ELK is named after three tools from the company Elastic. Elasticsearch stores and searches, Logstash processes events on the way in, and Kibana is the web interface. A fourth tool, Filebeat, collects log files. Elastic calls the family the Elastic Stack, but most people still say ELK.
Log Aggregation and Retention showed the five steps of every central log system: collect, ship, parse and enrich, store and index, search. ELK gives each step to a tool: Filebeat collects and ships, Logstash parses and enriches, Elasticsearch stores and indexes, and Kibana searches and draws charts.
Elasticsearch: the shelves and the catalogue
Elasticsearch is a search and analytics store built on Apache Lucene, a Java search library. It keeps documents: JSON objects, such as one shop-demo log line split into fields. You add and query them through a REST API, plain HTTP requests with JSON bodies, on port 9200.
Documents live in an index, a named collection such as shop-logs-2026.11.27. Its mapping records each field's type. Without one, Elasticsearch guesses from the first document with the field: status becomes a number, and strings such as route become both text, for word search, and a keyword, for exact matches.
For text, Elasticsearch builds an inverted index: a list of every word and the documents that contain it, like the index at the back of a book. A search for timed looks the word up instead of reading every line, so it stays fast with millions of lines. A new document becomes searchable after the next refresh, when Elasticsearch opens new data to search, by default each second.
Each index is split into shards, pieces that Elasticsearch spreads across the nodes, the servers, of its cluster. By default an index has one primary shard and one replica, a copy kept on another node in case the first is lost. Elasticsearch never puts a replica on the same node as its primary, so on the lab's single node every replica stays unassigned.
So the lab's health is yellow: all the data is there, but nothing is copied. The daily index names help with retention: deleting a whole index is one cheap request, far lighter than deleting millions of documents.
Logstash, Filebeat and Kibana
Logstash is a processing pipeline that runs on the Java virtual machine (JVM). A pipeline has three stages, each built from plugins: inputs receive events, filters parse and enrich them, and outputs send them on. In the lab, the beats input listens for Filebeat, the json and date filters turn a line into fields with the right time, and the elasticsearch output writes the document.
Enriching means adding what the line lacks, such as a country looked up from an IP address. Logstash can also send each event to several outputs.
Filebeat is a lightweight shipper written in Go. It tails files: like tail -f, it reads new lines as they are written. It records how far it has read each file in its registry, so after a restart it carries on instead of sending everything again. If Logstash is busy or down, Filebeat keeps retrying.
Kibana is the web interface, on port 5601. Its Discover page searches and filters documents by field, and Lens draws charts. Like Grafana in lesson 9, it stores none of the data: it asks Elasticsearch and draws the answer.
You do not always need Logstash. Filebeat can send straight to Elasticsearch, and light work such as decoding JSON can happen in a Filebeat processor or an Elasticsearch ingest pipeline, processing steps that run inside Elasticsearch. The flowchart shows when Logstash earns its place:
By that test, shop-demo's clean JSON needs only Filebeat. The lab adds Logstash anyway, so that you see the parsing step.
How the pieces fit in the lab
The lab folder course-labs/open-source-observability-stack/05-elk runs six containers on the obs-lab network. shop-demo and loadgen are the app and traffic from lesson 2. The app appends every JSON line to /var/log/shop-demo/shop-demo.log in the shop-logs volume, which Filebeat mounts read-only.
Logstash takes each event's time from the app's timestamp field and writes it to shop-logs- plus the date in UTC. Lesson 17 walks through the Filebeat and Logstash files.
Resource reality check: memory and security
Elasticsearch and Logstash run on the JVM, which reserves a heap, the memory where Java keeps its objects. Elasticsearch also needs memory outside the heap, for the operating system's file cache, so Elastic's rule is a heap of at most half the memory. Here is the lab's Elasticsearch service, trimmed:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:9.5.7
environment:
node.name: es01
cluster.name: obs-lab
discovery.type: single-node # one node that elects itself
xpack.security.enabled: "false" # LAB ONLY: no passwords, no TLS
ES_JAVA_OPTS: "-Xms1g -Xmx1g" # LAB ONLY: a fixed 1 GB heap
ports:
- "127.0.0.1:9200:9200" # localhost only
single-node means the node never looks for others, and failed start-up checks, such as Linux's vm.max_map_count, stay warnings. In production you let Elasticsearch size its heap from the container's memory. Logstash gets 512 MB instead of its default 1 GB. Give Docker 6 to 8 GB for this lab.
Turning security off is the biggest shortcut. Recent Elasticsearch versions set up passwords and TLS encryption on their first start. Without them, anyone who can reach port 9200 can read, change or delete any index with plain HTTP requests. The lab risks it only because the port listens on 127.0.0.1. Never do this in production.
Alternatives: Grafana Loki and OpenSearch
Grafana Loki indexes only labels, such as service, and stores the log text compressed in chunks, often in object storage. That makes it much cheaper to run, but a word search reads the chunks of the matching streams instead of looking the word up. OpenSearch is a fork of Elasticsearch and Kibana, started in 2021 after Elastic's licence change, with OpenSearch Dashboards instead of Kibana. It uses the Apache 2.0 licence and is a Linux Foundation project.
Check yourself
The lab's cluster health is yellow, and a teammate wants to rebuild it from scratch. Is any log data missing?
No. Yellow means every primary shard is assigned and only replicas are not, because a replica never sits on the same node as its primary. A rebuild would end yellow again; only red means missing primaries.
Your app already writes JSON lines and you only need them in Elasticsearch. Do you need Logstash?
No. Filebeat can send straight to Elasticsearch and decode the JSON with a processor or an ingest pipeline. Logstash pays off for heavy parsing, enrichment or several outputs, since Filebeat has only one.
Why does a search for timed across millions of lines return in under a second, when grep over the same file takes much longer?
Elasticsearch looks the word up in its inverted index, which already lists the documents containing each word. grep has no index, so it must read every line each time.