Skip to content

Elasticsearch aliases and rollover

Use aliases to abstract index names and rollover to roll write traffic to a new index when size or age limits hit. Patterns for zero-downtime reindex and write switching.

Aliases are how Elasticsearch hides physical index names from application code, and rollover is how time-series indices grow without manual intervention. This article shows the two operational patterns that depend on them: (1) automatic write-alias rollover for logs and metrics, and (2) read-alias swap for zero-downtime reindex. Audience is operators or developers building applications against Elasticsearch indices that need to evolve over time.

How to verify

Check existing aliases and rollover status:

curl -sk -u elastic:"$PW" 'https://es:9200/_cat/aliases?v'
curl -sk -u elastic:"$PW" 'https://es:9200/_alias/logs?pretty'
curl -sk -u elastic:"$PW" 'https://es:9200/logs/_stats?level=indices&filter_path=indices.*.primaries.docs.count,indices.*.primaries.store.size_in_bytes'
curl -sk -u elastic:"$PW" 'https://es:9200/_cat/indices/logs-*?v&s=index'

Healthy: at most one index in an alias has is_write_index: true; the count of indices behind the alias matches your rollover/retention math.

What’s happening

An alias is a pointer that can refer to multiple indices. A query against logs searches every index attached to the alias. A write to logs requires exactly one of those indices to be marked is_write_index: true.

Two operational uses:

  • Write alias + rollover — application writes to logs. ILM (or manual rollover) creates logs-000002 when conditions hit (size, age, doc count) and flips is_write_index. Application doesn’t know.
  • Read alias swap — application reads from products. You build products_v2 offline (reindex with new mapping), then atomically swap the alias from products_v1 → products_v2.

Both patterns let physical indices change without coordinating with application code or worrying about downtime.

The procedure

Pattern A: Write alias with rollover (logs/metrics)

1. Bootstrap the initial index and alias:

curl -sk -u elastic:"$PW" -X PUT 'https://es:9200/logs-000001' \
  -H 'Content-Type: application/json' \
  -d '{
    "aliases": {
      "logs": {"is_write_index": true}
    }
  }'

The index name MUST end in a numeric suffix (-NNNNNN) for rollover to compute the next name automatically.

2. Write to the alias from Filebeat/Logstash/application:

curl -sk -u elastic:"$PW" -X POST 'https://es:9200/logs/_doc' \
  -H 'Content-Type: application/json' \
  -d '{"@timestamp": "2026-06-02T12:00:00Z", "message": "hello"}'

3. Roll over by condition — explicit API:

curl -sk -u elastic:"$PW" -X POST 'https://es:9200/logs/_rollover' \
  -H 'Content-Type: application/json' \
  -d '{
    "conditions": {
      "max_age": "7d",
      "max_primary_shard_size": "30gb",
      "max_primary_shard_docs": 200000000
    }
  }'

If any condition is met, Elasticsearch creates logs-000002, swings is_write_index to it, and returns rolled_over: true. If no conditions are met, it returns rolled_over: false and does nothing.

4. Let ILM run it on a schedule. The ILM rollover action checks the conditions every cycle and triggers automatically.

Pattern B: Zero-downtime reindex via alias swap

1. Application reads through alias only. The application should never reference products_v1 directly:

curl -sk -u elastic:"$PW" -X POST 'https://es:9200/_aliases' \
  -H 'Content-Type: application/json' \
  -d '{
    "actions": [
      {"add": {"index": "products_v1", "alias": "products"}}
    ]
  }'

2. Create the v2 index with the new mapping:

curl -sk -u elastic:"$PW" -X PUT 'https://es:9200/products_v2' \
  -H 'Content-Type: application/json' \
  -d '{
    "settings": {"number_of_shards": 2, "number_of_replicas": 1, "refresh_interval": "-1"},
    "mappings": {
      "properties": {
        "name": {"type": "text", "fields": {"keyword": {"type": "keyword"}}},
        "price": {"type": "double"},
        "embedding": {"type": "dense_vector", "dims": 384}
      }
    }
  }'

refresh_interval: -1 disables refresh during bulk reindex for throughput. Re-enable after.

3. Reindex from v1 to v2:

curl -sk -u elastic:"$PW" -X POST 'https://es:9200/_reindex?wait_for_completion=false' \
  -H 'Content-Type: application/json' \
  -d '{
    "source": {"index": "products_v1", "size": 1000},
    "dest":   {"index": "products_v2"},
    "script": {"source": "ctx._source.remove(\"legacy_field\");"}
  }'

The response returns a task_id. Monitor:

curl -sk -u elastic:"$PW" 'https://es:9200/_tasks/$TASK_ID?pretty'

4. Verify counts and a sample query:

curl -sk -u elastic:"$PW" 'https://es:9200/products_v1/_count'
curl -sk -u elastic:"$PW" 'https://es:9200/products_v2/_count'
curl -sk -u elastic:"$PW" -X PUT 'https://es:9200/products_v2/_settings' \
  -H 'Content-Type: application/json' \
  -d '{"refresh_interval": "1s"}'

5. Atomic alias swap:

curl -sk -u elastic:"$PW" -X POST 'https://es:9200/_aliases' \
  -H 'Content-Type: application/json' \
  -d '{
    "actions": [
      {"remove": {"index": "products_v1", "alias": "products"}},
      {"add":    {"index": "products_v2", "alias": "products"}}
    ]
  }'

The entire actions array is atomic — the cluster never observes a state where products points to neither or both.

6. Wait a release cycle, then delete v1. If rollback is needed, swap the alias back.

Common pitfalls

  • Writing directly to logs-000001 bypassing the alias. Bypasses rollover. Always write to the alias.
  • Multiple is_write_index: true would be an error — rollover prevents this. But manual alias edits can break it. Audit with _cat/aliases.
  • Aliasing patterns vs aliases. _alias defines named aliases. _index_template defines settings for index patterns. Don’t confuse them.
  • Filtered aliases. An alias can include a query filter — useful for multi-tenant separation, but the filter is applied on every query. Be aware of the cost.
  • Reindex doesn’t copy settings or aliases. You must recreate them on the destination.
  • _reindex halts on a script error by default. Use conflicts: proceed for best-effort but log failures, or fix the script.

In the engagements we run, aliases and rollover are foundational — almost every production index pattern uses one of them. The discipline is to treat physical index names as ephemeral and aliases as the contract with application code. That discipline pays dividends every time we evolve a mapping, change shard counts, or recover from a bad ingest. See /en/services/managed-operations/ for how we run search infrastructure with continuous index evolution.