Wildcard alias for Elastic index

Viewed 405

I've got an Elastic index transactions-internal and would like to point all the names like transactions-([a-z]+)-internal to this index using alias, so all the requests like

GET /transactions-a-internal/_search
GET /transactions-b-internal/_search
GET /transactions-c-internal/_search
...
etc

should give the same result as

GET /transactions-internal/_search

I've tried

POST /transactions-internal/_alias/transactions-*-internal

but it returned

Invalid alias name [...] must not contain the following characters [ , \", *, \\, <, |, ,, >, /, ?]

Is there any "smart" solution for that? I would strongly prefer co configure it on Elastic side, not anywhere else.

2 Answers

You're almost there. It's the other way around, i.e. POST /<index>/_alias/<alias>

POST /transactions-*-internal/_alias/transactions-internal

UPDATE:

If you want the other way around, then you can use the following (note that an alias name cannot contain wildcard characters):

POST /_aliases
{
    "actions" : [
        { "add" : { "index" : "transactions-internal", "alias" : "transactions-a-internal" } },
        { "add" : { "index" : "transactions-internal", "alias" : "transactions-b-internal" } },
        { "add" : { "index" : "transactions-internal", "alias" : "transactions-c-internal" } }
    ]
}

Not quite sure if this is applicable to your situation but if you're starting from scratch a possible solution might be to use a index template.

PUT _index_template/transactions-internal
{
  "priority": 1,
  "template": {
    "aliases": {
      "transactions-internal": {}
    }
  },
  "index_patterns": [
    "transactions-*-internal"
  ],
  "composed_of": []
}

As I'm quite new to elastic I don't know if this template can be applied to an existing index.But this approach will work for new indizes in v 7.12.1

Related