How to name an alias with the dynamic part of a template pattern?

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser): 2.19

Describe the issue: Can’t name an index with the dynamic part of an index name template pattern

In my company we use opensearch for multiple types of documents in different indexes for multiple clients. So we have templates for each kind of document and an alias for the client, using the client id on the name i.e for the client_id 8 we would have the indexes: files-8, records-8… and the alias: client-8 assigned to files-8, records-8….

We have templates for each kind of document with pattern: files-*, records-*… But there is no way to assign the alias on the template as I would need to capture the dynamic part to assign the newly created, that could be done with a syntax like that maybe

"template": {
  "aliases": {
     "client-$1": {}
  }
}

so we could assign the newly created index to the client alias, but we could not find an option to assign it to the regex segment captured on the index pattern.

This forces us to manually assign the alias for each index to each client. Or, as the indexes are automatically created based on the template, check on each index operation if the alias is assigned and assign it otherwise, which is not ideal.

Is there a way to automatically create and assign the alias based on the dynamic part of index template pattern?

@sousu I’ve checked the documentation and GitHub, and didn’t find a built-in mechanism or workaround in OpenSearch that would allow dynamic alias naming.

You can file a Feature Request in OpenSearch GitHub. If you do so, please share the link here.

I found this reference of something that resembles of dynamically assigning a name to the index based on template, that would go something like:

PUT /_index_template/alias-template
{
  "index_patterns": [
    "something*"
  ],
  "template": {
    "settings": {
      "number_of_shards": 1
    },
    "aliases": {
      "{index}-alias": {}
    }
  }
}

but I could find no reference on documentation as how this semantics work, I assume it will name de alias “something-1-alias”. It’s not what I need but would indicate that there is already a similar feature that could facilitate my feature suggestion.

Would you have any more information on this?

I created an issue here: [Feature Request] Possibility to name an alias with the dynamic part of a template pattern · Issue #20122 · opensearch-project/OpenSearch

1 Like