Elasticsearch mget批量查询

来源:互联网 发布:mysql.host不存在 编辑:程序博客网 时间:2024/06/10 20:12
1、批量查询的好处


就是一条一条的查询,比如说要查询100条数据,那么就要发送100次网络请求,这个开销还是很大的
如果进行批量查询的话,查询100条数据,就只要发送1次网络请求,网络请求的性能开销缩减100倍


2、mget的语法


(1)一条一条的查询


GET /test_index/test_type/1
GET /test_index/test_type/2


(2)mget批量查询


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


{
  "docs": [
    {
      "_index": "test_index",
      "_type": "test_type",
      "_id": "1",
      "_version": 2,
      "found": true,
      "_source": {
        "test_field1": "test field1",
        "test_field2": "test field2"
      }
    },
    {
      "_index": "test_index",
      "_type": "test_type",
      "_id": "2",
      "_version": 1,
      "found": true,
      "_source": {
        "test_content": "my test"
      }
    }
  ]
}


(3)如果查询的document是一个index下的不同type种的话


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


(4)如果查询的数据都在同一个index下的同一个type下,最简单了


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


3、mget的重要性


可以说mget是很重要的,一般来说,在进行查询的时候,如果一次性要查询多条数据的话,那么一定要用batch批量操作的api
尽可能减少网络开销次数,可能可以将性能提升数倍,甚至数十倍,非常非常之重要











阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 巴啦小魔仙 芭啦啦 啦啦是什么意思 啦啦小魔仙 爱啦啦歌曲 啦啦啦啦啦啦啦啦啦 啦啦啦啦 吧啦啦 啦啦啦啦啦 吧啦啦小魔全集真人版 莎啦啦 真中啦啦 啦小魔仙 啦啦小魔 啦啦啦啦啦啦是什么歌 撒有啦啦是什么意思 啦吧啦小魔仙 啦啦啦啦啦啦 乌啦啦 噜啦啦儿歌 哆啦啦 可啦啦 美啦啦 呜啦啦 莎啦啦啦啦 无啦啦 巴啦啦啦啦 上戏优啦啦 卡啦啦 火啦啦 杜啦啦 布啦啦 呼啦啦啦啦 鲁啦啦 吧啦啦小魔图片 啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦啦啦 啦啦啦啦啦啦啦啦啦啦啦 啊啦啦啦 大家别聊天啦快点来拯救世界 一不小心无敌