Loading...

Create alias for indices in Elasticsearch

If you have multiple indices and build your visualizations and dashboard in Kibana, you might consider using an alias. The advantage is that the physical index name can always be removed, renamed, reindex. The alias gives you the flexibility that your Kibana objects remain consistent, but in the background you have to freedom to reorganize. This post illustrates two examples.

The first example is an environment case. In your development you have dev, a test system, a staging system and a production. Following curl command with JSON data, creates an alias dev for the indices fo-dev-*. The wildcard can be used.

curl -XPOST 'http://localhost:9200/_aliases' -d '
{
    "actions" : [
        { "add" : { "index" : "fo-dev-*", "alias" : "dev" } }
    ]
}'
{"acknowledged":true}

The second case is the alias stats for the indices metrics-*.

curl -XPOST 'http://localhost:9200/_aliases' -d '
{
    "actions" : [
        { "add" : { "index" : "metrics-*", "alias" : "stats" } }
    ]
}'
{"acknowledged":true}