跟我学Elasticsearch(12) 使用mget进行批量查询

[Toc]

1、为什么要批量查询

假如我们要查100个document,一个一个id查的话,需要发送100次网络请求,占用网络开销,用mget进行批量查询的话,只要发送1次网络请求,网络开销减小100倍。

2、mget的语法

(1) 同一index同一type

GET /test_index/test_type/_mget
{
   "ids": [1, 2]
}

(2) 同一index不同type

GET /test_index/_mget
{
   "docs" : [
      {
         "_type" :  "test_type",
         "_id" :    1
      },
      {
         "_type" :  "test_type2",
         "_id" :    2
      }
   ]
}

(3) 不同idex

GET /_mget
{
   "docs" : [
      {
         "_index" : "test_index",
         "_type" :  "test_type",
         "_id" :    1
      },
      {
         "_index" : "test_index2",
         "_type" :  "test_type2",
         "_id" :    2
      }
   ]
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容