2

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.

P. Pedrycz
  • 41
  • 1
  • 9

2 Answers2

2

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" } }
    ]
}
Val
  • 207,596
  • 13
  • 358
  • 360
  • `no such index [...] transactions-*-internal`, as I said: the only index I have currently is `transactions-internal` but I'd like to have it accessible under different names – P. Pedrycz Mar 31 '20 at 07:48
  • Thanks @Val, upvoted, but not marked as resolved - the whole point was to have it configured dynamically, without specifying all the names. Probably I'm gonna need some HTTP proxy for that if it's not possible inside Elastic itself. – P. Pedrycz Mar 31 '20 at 08:00
  • I'm curious, may I ask you to explain your use case in a bit more details? There might be other ways to solve your problem. – Val Mar 31 '20 at 08:12
  • We maintain third-party enterprise application which is expecting separate index for every introduced datasoruce (even datasources which we don't need on some environments). No full access to the source code = no other way to solve the problem I guess :) – P. Pedrycz Mar 31 '20 at 09:05
  • 1
    Have you tried investigating [filtered aliases](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html#filtered), that can give the illusion of separate indices, yet you only need to manage a single one. – Val Mar 31 '20 at 09:07
  • @Val sir, can you pls show some path regarding this: https://stackoverflow.com/questions/60923264/elasticsearch-add-password-to-only-delete-index-api – DARK_C0D3R Mar 31 '20 at 15:58
  • with filtered aliases we still need to add every single alias manually so I guess it's not an answer – P. Pedrycz May 15 '20 at 15:36
1

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

fstrelczuk
  • 11
  • 1
  • 3