Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add alias to index from template?

How do you add an alias to an index using a template?

If I look at my current templates there are empty sections named aliases in mappings and in the parent of mappings. I can't seem to find much documentation indicating their use. What I'm hoping to do is not have to execute an alias add after the index is created.

Thanks, Pat

like image 828
tuckerpm Avatar asked Jan 07 '23 06:01

tuckerpm


1 Answers

When creating an index template, the aliases section contains the aliases that you want to be created at the same time a new index is created. For instance, with the command below, every time a new index whose name matches index* is created, then the aliases named my_alias1 and my_alias2 are also created at the same time.

curl -XPUT localhost:9200/_template/my_template -d '
{
    "template" : "index*",
    "settings" : {
        "number_of_shards" : 1
    },
    "aliases" : {
        "my_alias1" : {},
        "my_alias2" : {}
    }
}'

UPDATE

Note that as of ES6, template has been renamed to index_patterns:

curl -XPUT localhost:9200/_template/my_template -d '
{
    "index_patterns" : "index*",
    "settings" : {
        "number_of_shards" : 1
    },
    "aliases" : {
        "my_alias1" : {},
        "my_alias2" : {}
    }
}'
like image 159
Val Avatar answered Jan 15 '23 04:01

Val