Log Aggregation with the ELK Stack for Java Services
Fast recall
Quick revision
Core answer
Understanding of the log pipeline from application to search UI, and why structured logging is essential for it.
Sending plain-text logs to Elasticsearch, which requires fragile Grok parsing in Logstash and breaks on log format changes.
Mention Filebeat as a lightweight alternative to Logstash for shipping, the Elastic Common Schema (ECS) field naming convention, and index lifecycle management for cost control.
Interview-ready guide
Interview answer
The ELK stack centralizes logs from all services and instances into a single searchable system — without it, debugging requires SSH access to individual pods and grep across log files, which doesn't scale beyond a handful of services.
The pipeline
- Spring Boot emits JSON logs to stdout; Filebeat (a lightweight log shipper) reads the container's stdout and forwards log lines to Logstash or directly to Elasticsearch
- Logstash parses, filters, and enriches log events before indexing them — add a
geoipfilter for IP addresses, adatefilter to parse custom timestamp formats, agrokfilter for plain-text logs that can't be sent as JSON - Elasticsearch indexes each log entry as a document; Kibana provides the search and visualization interface
Kibana Discover — searching logs
- Select the log index and a time range;
level: ERROR AND service: orders-servicereturns all errors from the orders service in the selected window - KQL (Kibana Query Language) supports field-level filtering, wildcards, and range queries; more powerful than full-text search for structured logs
Kibana dashboards for observability
- Error rate panel:
count where level: "ERROR" by @timestamp per 5m— visualizes error frequency over time; spike in errors correlates with a deployment or infrastructure event - Correlate with Jaeger: the
traceIdfield in each log entry links to the distributed trace in Jaeger; configure Kibana's field formatter to generate a clickable Jaeger link from the trace ID
Index management
- Log indices grow quickly — configure ILM (Index Lifecycle Management) to roll over indices when they exceed 50GB, move to warm storage after 7 days, and delete after 30 days; without ILM, Elasticsearch disk usage grows without bound
- Use data streams with ILM in Elasticsearch 7.9+ for automatic index rollover with a single named stream
Log Aggregation with the ELK Stack for Java Services
Direct Answer
Spring Boot emits JSON logs via Logstash Logback Encoder. Logstash (or Filebeat) ships them to Elasticsearch. Kibana provides search, dashboards, and alerting over the indexed logs. Correlation IDs and trace IDs in the JSON make cross-service log investigation possible.
Common Mistakes & Pitfalls
Sending plain-text logs to Elasticsearch, which requires fragile Grok parsing in Logstash and breaks on log format changes.
Check your understanding
Answer these without looking back at the article.
- What is the difference between Logstash and Filebeat?
- How would you handle log aggregation in a Kubernetes-based deployment?
- What is the Elastic Common Schema and why does it matter?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.