Loading...

Loki vs Elasticsearch: how to choose

Loki and Elasticsearch take opposite positions on the same question: how much of a log should you index? Elasticsearch indexes the content, so any field is queryable and aggregations are fast. Loki indexes only labels and stores the log body compressed, so queries filter by label and then scan.

That decision drives everything downstream — cost, query shape and operational burden. Loki is dramatically cheaper to store and simpler to run, because there is far less index to build, hold and shard. Its constraint is that a query which cannot be narrowed by labels becomes a scan, and a scan over a wide time range is slow.

Elasticsearch costs more in storage and in operational attention, and pays it back in query power. Full-text search across arbitrary fields, aggregations, and analytics over log content are things Loki is not built to do well.

Label cardinality is the thing that will hurt you

Loki's efficiency depends entirely on keeping label cardinality low. Labels should describe the stream — namespace, app, container, level — and never the request. Putting a user ID, request ID, trace ID or pod IP in a label creates a separate stream per value, and the index Loki was designed to avoid building reappears in the worst possible shape.

This is the single most common way a Loki deployment goes wrong, and it degrades gradually rather than failing outright: ingestion slows, queries get expensive, and memory grows until someone investigates. Decide the label schema before you onboard services, and treat adding a label as a change requiring review.

Decision matrix: which one fits your situation

Your situationUseWhy
Kubernetes logs, already running GrafanaLokiSame query ergonomics and datasource as your metrics; cheap object storage retention.
Full-text search across log contentElasticsearchLoki cannot do this well by design — it does not index the body.
Analytics and aggregations over log fieldsElasticsearchAggregations are what the inverted index is for.
Storage cost is the binding constraintLokiObject storage plus a small index is far cheaper than a full content index.
Security analytics, SIEM-style correlationElasticsearchCorrelation across arbitrary fields is the core requirement, and Loki is the wrong shape.
Small team, no search specialistLokiFar less to tune. Elasticsearch cluster management is a real skill set.

Frequently asked questions

Is Loki really cheaper?

Substantially, for the usual Kubernetes case, and for a structural reason rather than a pricing one: you are storing compressed logs in object storage with a small index instead of a full content index on fast disks. The saving evaporates if you misuse labels — high cardinality recreates the index cost you were avoiding, plus memory pressure.

Can I run both?

Yes, and it is a reasonable split: Loki for the high-volume application logs where you almost always know the service and time range, Elasticsearch for the subset needing full-text search or long-term analytics — audit and security logs, typically. The cost is two pipelines and two mental models, so route deliberately rather than duplicating everything into both.

How does LogQL compare to Elasticsearch queries?

LogQL will feel immediately familiar if you know PromQL: select streams by label, then filter and optionally aggregate. It is well suited to "show me errors from this service in this window". It is not a search language — if your question begins with an unknown service and a string to find everywhere, Elasticsearch is the right tool.

What about OpenSearch?

OpenSearch is the fork of Elasticsearch that AWS created after the 2021 licence change; since September 2024 it has been governed by the Linux Foundation's OpenSearch Software Foundation rather than by AWS alone. For log use cases it is broadly comparable. Everything above about indexing trade-offs applies equally. Choose between them on licensing, managed-service availability and ecosystem preference rather than on log-handling capability.