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 #
| Criterion | Loki | Elasticsearch |
|---|---|---|
| Index | labels only (+ structured metadata and Bloom filters in 3.x) | inverted index on fields and text |
| Language | LogQL | KQL, Lucene, ES|QL, Query DSL |
| Full-text search | filter on lines after stream selection | instant, with relevance scoring |
| Storage | object (S3, GCS, Azure Blob) | node disks, hot/warm/cold/frozen tiers |
| Retention | compactor (retention_period) | ILM (Index Lifecycle Management) |
| Strengths | cost, simplicity, Grafana integration | search, 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 #
| Action | Command |
|---|---|
| Loki query | logcli query '{app="checkout"} |= "error"' --since=1h --limit=50 |
| List Loki labels | logcli labels app |
| Measure cardinality | logcli series '{env="prod"}' --analyze-labels |
| Elasticsearch search | curl -s "localhost:9200/logs-*/_search?q=message:error&size=5" |
| Index size | curl -s "localhost:9200/_cat/indices?v&s=store.size:desc" |
| ILM policies | curl -s "localhost:9200/_ilm/policy?pretty" |
Lab: measure storage cost #
- Send the same log file (at least 1 GB) to Loki with Grafana Alloy and to Elasticsearch with Filebeat or Elastic Agent.
- Compare used space: bucket or chunk directory size for Loki,
_cat/indicesfor Elasticsearch. - Time a search for a rare word over 24 hours in each tool.
- 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.
