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
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" : {}
}
}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With