24

The ElasticSearch Docs reads:

An alias can also be mapped to more than one index, and when specifying it, the alias will automatically expand to the aliases indices.

But when I try to add an alias to 2 indices and write to both, neither seem to get updated with the document. If I remove one of the aliases, it will write correctly to the alias that still exists.

Fails with multiple write aliases:

$ curl -XGET 'http://localhost:9200/_aliases'

result:

{
  "dev_01": {
    "aliases": {
      "dev_read": {},
      "dev_write": {}
    }
  },
  "dev": {
    "aliases": {
      "dev_write": {}
    }
  }
}

Works with single alias:

$ curl -XGET 'http://localhost:9200/_aliases'

result:

{
  "dev_01": {
    "aliases": {
      "dev_read": {},
      "dev_write": {}
    }
  },
  "dev": {
    "aliases": {}
  }
}

Does elasticsearch support writing to multiple indices? Are aliases Read-Only if pointed at multiple indices?

Saeed Zhiany
  • 2,051
  • 9
  • 30
  • 41
MattoTodd
  • 14,467
  • 16
  • 59
  • 76

1 Answers1

32

the answer is No

So it appears I should have triaged this a beep deeper, but the response my client gets from es is:

ElasticSearchIllegalArgumentException[Alias [dev_write] has more than one indices associated with it [[dev_01, dev]], can't execute a single index op

Just wish the docs were a little more explicit up front, as they confused me a bit

At first seems to imply you can:

The index aliases API allow to alias an index with a name, with all APIs automatically converting the alias name to the actual index name. An alias can also be mapped to more than one index...

Associating an alias with more than one index are simply several add actions...

Further down the page lets you know you can not:

It is an error to index to an alias which points to more than one index.

matt
  • 125
  • 12
MattoTodd
  • 14,467
  • 16
  • 59
  • 76
  • 1
    Correct, the reason for the answer is: how can elasticsearch know which index is supposed to hold that new document if the alias points to multiple indices? Indexing is a single index operation, like any write operation, thus it needs to execute on a specific index. – javanna Oct 30 '13 at 12:43
  • 2
    @javanna: I would rather say: because it is not implemented. I could think of a few ways to specify where and how to write to. – soulmerge May 12 '14 at 09:15
  • @soulmerge sure it would be possible by specifying where to write to, which would make it less useful to use the alias though. There is a reason if it's not supported. If you have better ideas though feedback is more than welcome! – javanna May 12 '14 at 12:56
  • 1
    @soulmerge we can publicly discuss this, just open an issue at http://www.github.com/elasticsearch/elasticsearch/issues or send a message to our mailing list. – javanna May 19 '14 at 12:27
  • 2
    The strange thing is I'm virtually certain this used to work on early versions of ElasticSearch. I used to rely on the behaviour so the incremental updates could flow to two indexes while a full index rebuild was in progress. – Yeroc Apr 21 '20 at 23:02
  • I think having single alias for multiple index is a good choice where two indexes are highly correlated in their domain but need a logical separation because of data constraints. We can specify specific update instructions but still want single alias to work – c0der512 Oct 17 '22 at 21:15
  • Issue about adding this behavior https://github.com/elastic/elasticsearch/issues/68003 – Ben Alavi Nov 15 '22 at 16:36