Reputation: 718
I know that I can put alias names for existing indexes via
POST /_aliases
{
"actions" : [
{ "add" : { "index" : "my-index-000001", "alias" : "alias1" } }
]
}
or (seems to be equal in outcome)
PUT /my-index-000001/_alias/alias1
but is it also possible to create an alias via patterns, so that new created indexes already come with an alias?
so when i do this:
POST /_aliases
{
"actions" : [
{ "add" : { "index" : "my-index-*", "alias" : "alias1" } }
]
}
All indexes created in the future which match pattern my-index-* will automatically come with alias alias1?
Upvotes: 0
Views: 1387
Reputation: 1000
Yes it is possible. you can see this link. You need to define an index template.
PUT _template/template_1
{
"index_patterns" : ["te*"],
"settings" : {
"number_of_shards" : 1
},
"aliases" : {
"alias1" : {}
}
}
Upvotes: 0
Reputation: 217304
Yes, you can do it like this using an index template:
PUT _index_template/my_template
{
"index_patterns": ["my-index-*"],
"template": {
"settings": {
"number_of_shards": 1
},
"aliases": {
"alias1": { }
},
"mappings": {
"properties": {
...
}
}
}
}
Note that if you're on a version before 7.8, the syntax is a little bit different:
PUT _template/my_template
{
"index_patterns": ["my-index-*"],
"settings": {
"number_of_shards": 1
},
"aliases": {
"alias1": { }
},
"mappings": {
"properties": {
...
}
}
}
Upvotes: 1