TExcelTAD

Fluent Bit & OpenSearch

The other common log stack, older than Loki and still everywhere: Fluent Bit collects and ships, OpenSearch (or Elasticsearch) indexes every field and word, and OpenSearch Dashboards (or Kibana) searches and visualises. OpenSearch is the Apache-2.0 fork of Elasticsearch, created by AWS in 2021 and now run by the OpenSearch Software Foundation under the Linux Foundation; the APIs used here are the same in both.

Loki vs OpenSearch

The deciding difference is what gets indexed:

Loki OpenSearch / Elasticsearch
index stream labels only every field (and full text) of every document
ingest cost low (compress and store) high (analyse and index everything)
storage object storage, cheap SSD-backed shards and replicas
query pick streams, then scan text lookup in the inverted index: fast "needle in a haystack" over months
strengths cheap at scale, Prometheus-like labels, Grafana integration full-text search, aggregations on any field, security analytics (SIEM)

This model shows the trade-off on 20,000 lines: an inverted index (term → line numbers) answers a rare-term search by lookup but costs a large structure; label-only indexing stores almost nothing but must scan every line of the selected streams:

python · try it yourself
import random

random.seed(1)
words = ["redirect", "created", "cache", "miss", "hit", "slow", "status", "route", "ok", "user"]
lines = []
for i in range(20000):
    pod = f"linkly-{i % 4}"
    text = " ".join(random.choice(words) for _ in range(8))
    if i == 13777:
        text += " deadlock detected"                       # the needle
    lines.append((pod, text))

# OpenSearch-style: an inverted index over every word
inverted = {}
for n, (_, text) in enumerate(lines):
    for w in set(text.split()):
        inverted.setdefault(w, []).append(n)
postings = sum(len(v) for v in inverted.values())

# Loki-style: an index of streams (label sets) only
streams = {}
for n, (pod, _) in enumerate(lines):
    streams.setdefault(pod, []).append(n)

hits = inverted.get("deadlock", [])
print(f"inverted index: {len(inverted)} terms, {postings} postings; 'deadlock' -> lines {hits} (1 lookup)")
scanned = found = 0
for pod, ids in streams.items():                           # {app="linkly"} selects all 4 streams
    for n in ids:
        scanned += 1
        if "deadlock" in lines[n][1]:
            found += 1
print(f"label index: {len(streams)} streams; 'deadlock' found {found}x after scanning {scanned} lines")
scanned_one = len(streams["linkly-1"])
print(f"with {{pod=\"linkly-1\"}} in the selector: {scanned_one} lines to scan")
inverted index: 12 terms, 113919 postings; 'deadlock' -> lines [13777] (1 lookup)
label index: 4 streams; 'deadlock' found 1x after scanning 20000 lines
with {pod="linkly-1"} in the selector: 5000 lines to scan

Neither is "better". Teams that mostly ask "show me errors for this service in the last hour" save a lot with Loki; teams that search for an IP or a user ID across 90 days of everything need an inverted index. Many organisations run both: Loki for application logs, OpenSearch for security and audit logs.

Fluent Bit

Fluent Bit is a small C agent (a CNCF graduated project, part of Fluentd's family) that runs as a DaemonSet on every node: inputs (tail files, systemd journal, OTLP…) → parsers and filters (Kubernetes metadata, modify, grep, Lua) → outputs (OpenSearch, Elasticsearch, Loki, S3, Kafka, OTLP, …). It can feed Loki too; the choice of agent and store are independent.

Its newer YAML configuration format (the classic .conf format still works):

yaml
# fluent-bit.yaml
service:
  flush: 1
  log_level: info
  http_server: on                     # /api/v1/metrics/prometheus for its own metrics
  storage.path: /var/fluent-bit/state # filesystem buffering survives restarts and outages

parsers:
  - name: linkly-json
    format: json
    time_key: time
    time_format: '%Y-%m-%dT%H:%M:%S%z'

pipeline:
  inputs:
    - name: tail
      path: /var/log/containers/linkly-*.log
      tag: kube.*
      multiline.parser: cri           # the containerd/CRI-O log line format (joins split lines)
      db: /var/fluent-bit/state/tail.db  # read positions
      storage.type: filesystem
  filters:
    - name: kubernetes                # adds pod, namespace, labels, annotations
      match: kube.*
      merge_log: on                   # parse the JSON inside the "log" field into fields
      keep_log: off
    - name: grep
      match: kube.*
      exclude: log ^GET /healthz
  outputs:
    - name: opensearch
      match: kube.*
      host: opensearch.logging.svc
      port: 9200
      tls: on
      http_user: fluent-bit
      http_passwd: ${OPENSEARCH_PASSWORD}
      logstash_format: on             # daily indices: linkly-2026.01.01
      logstash_prefix: linkly
      suppress_type_name: on
      retry_limit: false              # keep retrying (with filesystem buffering)

The Fluent Bit Helm chart (fluent/fluent-bit) installs it as a DaemonSet with the Kubernetes filter and RBAC preconfigured.

OpenSearch: indices, mappings, retention

bash
# sample session against an OpenSearch cluster
$ curl -s -u admin:$PW 'https://opensearch:9200/_cat/indices/linkly-*?v&s=index'
health status index             uuid                   pri rep docs.count store.size
green  open   linkly-2026.01.01 3Xr0gP8xQ2yJ0bq1V9mLkA   1   1     184213     61.2mb
green  open   linkly-2026.01.02 kV8w2LmPRZ6s1a0C7tYbQg   1   1     201877     66.9mb

$ curl -s -u admin:$PW -H 'Content-Type: application/json' 'https://opensearch:9200/linkly-*/_search' -d '{
  "size": 2,
  "query": { "bool": { "filter": [
    { "term": { "level": "ERROR" } },
    { "range": { "@timestamp": { "gte": "now-1h" } } } ] } },
  "aggs": { "by_msg": { "terms": { "field": "msg.keyword" } } }
}' | jq '.aggregations.by_msg.buckets'
[
  { "key": "create link failed", "doc_count": 41 },
  { "key": "redis timeout", "doc_count": 3 }
]

Operational must-haves:

  • Index templates with explicit mappings (status as integer, trace_id as keyword), or dynamic mapping guesses types and a field that once held a string breaks every later document ("mapping conflict").
  • Retention through Index State Management (ISM; Elasticsearch calls it ILM): roll over daily or by size, move to warm nodes, delete after N days.
  • Limit fields per index (index.mapping.total_fields.limit): free-form JSON keys can create thousands of fields.
  • Size shards at tens of GB, not thousands of tiny ones.

Managed options: Amazon OpenSearch Service, Elastic Cloud. Check current pricing; log storage is often the largest observability bill.

Test yourself

What is the main architectural difference between Loki and OpenSearch?

  1. Loki is written in Java
  2. Loki indexes only stream labels; OpenSearch indexes every field and term
  3. OpenSearch can't store JSON
  4. Loki can't run in Kubernetes

What does Fluent Bit's kubernetes filter add?

  1. Prometheus metrics
  2. Pod, namespace, labels and annotations for each container log line
  3. TLS
  4. Retention

Why define an index template with explicit mappings in OpenSearch?

  1. To make searches slower
  2. So field types don't depend on the first document; dynamic guesses cause mapping conflicts
  3. It's required for Fluent Bit
  4. To enable Loki