RousselTMLEARNING

Observability

Grafana Loki vs Elasticsearch: the battle of log storage

A comparison between Loki, the Prometheus-inspired log system, and Elasticsearch, the reference full-text search engine.

1. Indexing philosophy #

Full indexing vs label-based indexing.

Elasticsearch: exhaustive indexing #

Available in: ✓ OSS ✓ Enterprise ✓ Cloud Loki open source, Enterprise Logs and Grafana Cloud Logs

Elasticsearch indexes every word of every log line. This enables almost instant searches on any term, but at the cost of very high CPU and RAM consumption and large storage volumes for the indexes.

Loki: the lightweight choice #

Inspired by Prometheus, Loki only indexes metadata (labels). Log content is compressed into chunks stored as is, preferably in object storage. Text searches are slower, because Loki reads and filters chunks on the fly, but the index is tiny and storage much cheaper: depending on volume and retention, the cost gap with Elasticsearch often reaches a factor of 3 to 10.

2. Cost and scalability #

TCO (total cost of ownership).

Financial comparison #

For cloud infrastructures generating several terabytes of logs per day, Loki is significantly cheaper. It can use inexpensive object storage (S3, GCS) without sacrificing stability.

3. Queries, cardinality and retention #

What changes for teams.

Two indexing models #

Indexing compared
CriterionLokiElasticsearch
Indexlabels only (+ structured metadata and Bloom filters in 3.x)inverted index on fields and text
LanguageLogQLKQL, Lucene, ES|QL, Query DSL
Full-text searchfilter on lines after stream selectioninstant, with relevance scoring
Storageobject (S3, GCS, Azure Blob)node disks, hot/warm/cold/frozen tiers
Retentioncompactor (retention_period)ILM (Index Lifecycle Management)
Strengthscost, simplicity, Grafana integrationsearch, analytics, SIEM, machine learning

The cardinality trap #

With Loki, each unique label combination creates a stream. Putting a request ID, user ID or IP address in a label creates millions of streams and collapses performance. Labels must stay few and stable (environment, application, namespace, level); everything else is filtered in the query.

# Bon : peu de labels, filtre dans la requête
{app="checkout", env="prod"} |= "timeout" | json | user_id="42"

# Mauvais : user_id comme label = un flux par utilisateur
{app="checkout", env="prod", user_id="42"}
Common mistake: Applying Elasticsearch habits to Loki by indexing every field as a label. Use structured metadata for high-cardinality fields instead.

4. Conclusion #

Should you migrate?

Recommendation #

Use Elasticsearch if you need to do complex security analysis or business intelligence on your logs. Use Loki for day-to-day technical observability: it is perfectly integrated with Grafana and costs much less to operate.

5. Commands to know and lab #

Query both engines from the command line.

Commands to know #

ActionCommand
Loki querylogcli query '{app="checkout"} |= "error"' --since=1h --limit=50
List Loki labelslogcli labels app
Measure cardinalitylogcli series '{env="prod"}' --analyze-labels
Elasticsearch searchcurl -s "localhost:9200/logs-*/_search?q=message:error&size=5"
Index sizecurl -s "localhost:9200/_cat/indices?v&s=store.size:desc"
ILM policiescurl -s "localhost:9200/_ilm/policy?pretty"

Lab: measure storage cost #

  1. Send the same log file (at least 1 GB) to Loki with Grafana Alloy and to Elasticsearch with Filebeat or Elastic Agent.
  2. Compare used space: bucket or chunk directory size for Loki, _cat/indices for Elasticsearch.
  3. Time a search for a rare word over 24 hours in each tool.
  4. Deliberately add a high-cardinality label on the Loki side and observe logcli series --analyze-labels.

Expected result: concrete figures on the cost versus search-speed trade-off for your own logs.

Related articles

Transforms and enrich: summarising and enriching data in Elasticsearch

Build entity-centric indices with pivot and latest transforms, and enrich documents at ingest time with enric…

OpenTelemetry and Elasticsearch: compatibility and architecture

Send OpenTelemetry to Elasticsearch: Collector and elasticsearch exporter, managed OTLP endpoint, APM Server,…

Ingesting OpenTelemetry logs into Elasticsearch

Collect and structure logs with the OpenTelemetry Collector (filelog receiver, operators, transform processor…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!