Databases 5 min read

Master Elasticsearch Index Aliases and Templates for Seamless Data Management

This guide explains how Elasticsearch index aliases and index templates work, illustrating their benefits for seamless index switching, grouping, view creation, and automated settings, and provides step‑by‑step code examples for creating, viewing, renaming, and deleting aliases and templates.

Linux Ops Smart Journey
Linux Ops Smart Journey
Linux Ops Smart Journey
Master Elasticsearch Index Aliases and Templates for Seamless Data Management

Index Alias

Alias Overview

In Elasticsearch, index aliases act like shortcuts or soft links that can point to one or more indices, providing flexibility such as seamless index switching, grouping multiple indices (e.g., recent days), creating view‑like subsets, and combining with routing.

Note: Elasticsearch ILM is typically used together with aliases.

Alias Operations

Create Alias

<code># Create indices first, then create alias
PUT /test0001
PUT /test0002
PUT /test0003

POST /_aliases
{
  "actions": [
    {
      "add": {
        "index": "test000*",
        "alias": "test"
      }
    }
  ]
}

# Create index with alias (common)
PUT /test1001
{
  "aliases": {
    "test": {}
  }
}
</code>

View Alias

<code>GET test/_alias</code>

Rename Alias

<code>POST /_aliases
{
  "actions": [
    {
      "remove": {
        "index": "test000*",
        "alias": "test"
      }
    },
    {
      "remove": {
        "index": "test100*",
        "alias": "test"
      }
    },
    {
      "add": {
        "index": "test000*",
        "alias": "test01"
      }
    },
    {
      "add": {
        "index": "test100*",
        "alias": "test01"
      }
    }
  ]
}
</code>

Delete Alias

<code>POST /_aliases
{
  "actions": [
    {
      "remove": {
        "alias": "test01",
        "index": "test*"
      }
    }
  ]
}
</code>

Index Template

Index Template Overview

Index templates define settings that are automatically applied when a new index is created, which is useful for scenarios like daily log indices that share the same mappings and configurations.

Templates only apply at index creation; changes do not affect existing indices.

Index Template Operations

Create

<code>PUT _index_template/k8s-logs
{
  "index_patterns": ["k8s-logs*"],
  "template": {
    "settings": {
      "index.number_of_shards": 3,
      "index.number_of_replicas": 1,
      "index.lifecycle.name": "jiaxzeng",
      "index.lifecycle.rollover_alias": "k8s-logs"
    }
  }
}
</code>

View

<code>GET _index_template/k8s-logs</code>

Modify

Modification uses the same full‑parameter request as creation (not shown).

Delete

<code>DELETE _index_template/k8s-logs</code>

Conclusion

Combining index aliases with templates enables seamless index version switching and clean separation between data and business layers, turning Elasticsearch index management into an automated, zero‑downtime process.

Search EngineElasticsearchILMIndex TemplateIndex Alias
Linux Ops Smart Journey
Written by

Linux Ops Smart Journey

The operations journey never stops—pursuing excellence endlessly.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.