user3658423
user3658423

Reputation: 1944

elasticsearch multi-index get request does not work

How can I use GET api on multiple indexes?

I tried the following but I keep getting index missing exception.

http://localhost:9200/index1,index2/_all/AUy25vKhcC3G2n2ukra3

Output:

{
  "error" : "IndexMissingException[[index1,index2] missing]",
  "status" : 404
}

Please help

Upvotes: 0

Views: 170

Answers (1)

monu
monu

Reputation: 698

Use multi-get api

Example:

POST test1/index1/1
{
  "name": "jon brick"
}
POST test2/index1/1
{
  "name": "sriji"
}
GET _mget
{
  "docs" : [
        {
            "_index": "test1",
            "_type":"index1",
            "_id" : "1"
        },
        {
            "_index": "test2",
            "_type":"index1",
            "_id" : "1"
        }
    ]
}

and the result is:

 {
   "docs": [
      {
         "_index": "test1",
         "_type": "index1",
         "_id": "1",
         "_version": 1,
         "found": true,
         "_source": {
            "name": "jon brick"
         }
      },
      {
         "_index": "test2",
         "_type": "index1",
         "_id": "1",
         "_version": 1,
         "found": true,
         "_source": {
            "name": "sriji"
         }
      }
   ]
}

Upvotes: 1

Related Questions