文章目录

  • 1.概述
    • 1.1 批量查询的好处
    • 1.2 使用mget进行查询操作
  • 3.见解
  • 4.bulk size的最佳大小

1.概述

转载:https://blog.csdn.net/qq_32252917/article/details/79771146

1.1 批量查询的好处

  1. 一条一条查询,需要发送多次,网络开销大,批量查询可以解决很多网络的开销
  2. 使用mget

1.2 使用mget进行查询操作

1)如果批量查询的对象不是在一个index中,那么可以用下面的语法

GET /_mget
{"docs":[{"_index":"test_index","_type":"test_type","_id":10},{"_index":"test_index","_type":"test_type","_id":8},{"_index":"ecommerce","_type":"product","_id":5}]
}

执行结果:结果也是封装到一个docs中

{"docs": [{"_index": "test_index","_type": "test_type","_id": "10","_version": 7,"found": true,"_source": {"test_field": "test_201712291052","test_field2": "test002"}},{"_index": "test_index","_type": "test_type","_id": "8","_version": 2,"found": true,"_source": {"test_field": "xxx81"}},{"_index": "ecommerce","_type": "product","_id": "5","_version": 1,"found": true,"_source": {"name": "zhuyan yagao","desc": "meibai jiankang","price": 54,"producer": "zhuyan producer","tags": ["fangzhu","meibai","jiankang"]}}]
}

2)如果获取的document是一个index中的不同type中的时候

GET /test_index/_mget
{"docs":[{"_type":"test_type","_id":10},{"_type":"test_type","_id":8}]
}

执行结果:

{"docs": [{"_index": "test_index","_type": "test_type","_id": "10","_version": 7,"found": true,"_source": {"test_field": "test_201712291052","test_field2": "test002"}},{"_index": "test_index","_type": "test_type","_id": "8","_version": 2,"found": true,"_source": {"test_field": "xxx81"}}]
}

3)如果document在同一个index,同一个type中时

GET /test_index/test_type/_mget
{"docs":[{"_id":10},{"_id":8}]
}

同样也可以查询

{"docs": [{"_index": "test_index","_type": "test_type","_id": "10","_version": 7,"found": true,"_source": {"test_field": "test_201712291052","test_field2": "test002"}},{"_index": "test_index","_type": "test_type","_id": "8","_version": 2,"found": true,"_source": {"test_field": "xxx81"}}]
}

上面3)中的语法也可以写成

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

结果:

{"docs": [{"_index": "test_index","_type": "test_type","_id": "1","_version": 2,"found": true,"_source": {"test_field": "xxx","test_field2": "xxx2"}},{"_index": "test_index","_type": "test_type","_id": "2","_version": 1,"found": true,"_source": {"test_field": "xxxxx000"}},{"_index": "test_index","_type": "test_type","_id": "10","_version": 7,"found": true,"_source": {"test_field": "test_201712291052","test_field2": "test002"}}]
}

3.见解

mget的重要性:很重要

一般来说,在进行查询的时候,如果一次性查询多条数据,那么一定要用batch批量操作的api,

尽可能一次请求网络,减少网路的消耗。

4.bulk size的最佳大小

bulk request会加载到内存中,如果太大的话,性能反而下降,因此需要反复尝试一个最大的bulk size。一般从10005000条数据开始,尝试逐渐增加。另外,如果看大小的话,最好在5M15M之间

【elasticsearch】elasticsearch 批量查询之mget相关推荐

  1. 批量查询,mget语法,mget批量查询(来自学习资料,第26节)

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

  2. elasticsearch版本不同,批量查询也不相同

    网上搜到批量查询可以通过TransportClient实现,但官方推荐使用RestHighLevelClient实现 注意: We plan on deprecating the TransportC ...

  3. elasticsearch索引的初始化操作以及marvel操作(增删改查),批量查询_mget,批量操作_bulk

    文中的简洁版都是使用marvel操作的 安装marvel插件的教程 https://blog.csdn.net/u013294097/article/details/100144725 1.创建索引之 ...

  4. Elasticsearch获取ES查询的所有结果,并批量导出Excel

    工作环境是内网所以不能截图. 搭建了ELK环境. 3500W个dic中查询数据,并要求导出excel. 从es中查询 status=500,返回为空,查询时间超过2000ms的数据 head插件查询出 ...

  5. elasticsearch 批量查询

    批量查询 _mget批量查询允许获取一个index,type,或者id的操作 用以下例子来演示 PUT test/_doc/1 {"counter":2,"tags&qu ...

  6. java操作elasticsearch实现批量添加数据(bulk)

    java操作elasticsearch实现批量添加主要使用了bulk 代码如下: //bulk批量操作(批量添加) @Testpublic void test7() throws IOExceptio ...

  7. ES(Elasticsearch)基本查询总结(含docker安装,python操作)

    全栈工程师开发手册 (作者:栾鹏) 架构系列文章 官网:https://www.elastic.co/guide/index.html 搜索语法:https://www.elastic.co/guid ...

  8. 【javaWeb微服务架构项目——乐优商城day07】——Elasticsearch介绍和安装及使用(安装kibana,安装ik分词器,Spring Data Elasticsearch,高级查询)

    文章目录 0.学习目标 1.Elasticsearch介绍和安装 1.1.简介 1.1.1.Elastic 1.1.2.Elasticsearch 1.1.3.版本 1.2.安装和配置 1.2.1.新 ...

  9. 26、ES中使用mget批量查询api(学习笔记,来自课程资料 + 自己整理)

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

最新文章

  1. 数据中心是虚拟现实的基石
  2. python代码画简单图-python绘制简单彩虹图
  3. 员工培训案例分析答案_培训主管的技巧:培训教材问题解析、培训实施分析报告(附案例)...
  4. leetcode 775. Global and Local Inversions | 775. 全局倒置与局部倒置(Java)
  5. php获取内存峰值,php内存\获取\使用
  6. android ROM ---(1)高通平台 Android O 升级学习
  7. swift 判断输入的字符串是否为数字
  8. mysql 电商项目(二)
  9. [zz]Win8应用商店管理小工具
  10. 测试过程中常用的linux命令之【删除指定的文件行】
  11. DSP28335定时器学习
  12. 用 logisim写一个 cpu
  13. 使用VC2005一些问题及解决方案(一)
  14. 如何准备PMP新版大纲考试?
  15. 计算机右键管理 已停止工作,管理器停止工作,详细教您怎么解决资源管理器已停止工作...
  16. java 数字转中文_使用Java将阿拉伯数字转换为中文数字(适配小数转换)
  17. 企业如何架设代理服务器联接互联网
  18. 5000字 大数据时代读书笔记_《大数据时代》读后感 读书笔记
  19. Win2003 Server磁盘配额揭密之删除篇
  20. Android系统字体加载流程

热门文章

  1. 500元/天,她们在闲鱼出租自己
  2. 消息称华为计划推出自有品牌电动汽车 官方重申不造车
  3. 票价最低10元 北京大兴国际机场线票价方案正式启用
  4. 暴风集团:冯鑫因涉嫌对非国家工作人员行贿被公安机关拘留
  5. 羡慕不来!华为高价招揽人才:应届博士年薪最高201万元
  6. 称洗澡时突遭电击 承租人起诉“自如”索赔77735元
  7. 阿里巴巴发布招聘微博:新财年新增超过1800岗位需求
  8. 小米组织架构再调整:手机部成立参谋部 朱磊出任参谋长
  9. python使用json序列化datetime类型问题处理
  10. HTML meta 标签 遇到meta http-equiv=refresh content=0; url=详解