2

I have a question about Elasticsearch.

If I have 2 indices IndexA and IndexB.

I put document docA with id "1" in IndexA, and I put document docB with id "1" in IndexB. The documents are of same doc type but different body (same structure but different values).

What will happen if I create an alias "alias1" which points to both IndexA and IndexB and do a get request of the following?

response = es_client.get(index="alias1", doc_type="doc_type", id="1")

Yundi Fei
  • 21
  • 2

1 Answers1

1

It is very easy to test, but in short you cannot issue a GET for a document using and alias that points to more than one index !

PUT index1/doc/1
{ "test": 1 }

PUT index2/doc/1
{ "test": 2 }

POST _aliases
{
    "actions" : [
        { "add" : { "index" : "index1", "alias" : "alias1" } },
        { "add" : { "index" : "index2", "alias" : "alias1" } }
    ]
}

GET alias1/doc/1

=>

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Alias [alias1] has more than one indices associated with it [[index2, index1]], can't execute a single index op"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Alias [alias1] has more than one indices associated with it [[index2, index1]], can't execute a single index op"
  },
  "status": 400
}
Val
  • 207,596
  • 13
  • 358
  • 360