elasticsearch多索引获取请求不起作用

时间:2015-04-14 08:08:58

标签: lucene elasticsearch

如何在多个索引上使用GET api?

我尝试了以下但是我一直在索引缺少异常。

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

输出:

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

请帮忙

1 个答案:

答案 0 :(得分:1)

使用multi-get api

示例:

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"
        }
    ]
}

结果是:

 {
   "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"
         }
      }
   ]
}