ITPub博客

首页 > IT基础架构 > > ES-mget批量查询

ES-mget批量查询

作者:飘絮絮絮丶 时间:2022-01-10 11:28:00 0 删除 编辑

批量查询的好处

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

mget语法

  • 一条一条的查询 GET /test_index/test_type/1 GET /test_index/test_type/1
  • 批量查询(index不同)
GET  /_mget
{
"docs": [
{
"_index": "testa_index",
"_type": "testa_type",
"_id": 1
},
{
"_index": "testb_index",
"_type": "testb_type",
"_id": 2
}
]
}
  • 批量查询(index相同,type不同)
GET  test_index/_mget
{
"docs": [
{
"_type": "testa_type",
"_id": 1
},
{
"_type": "testb_type",
"_id": 2
}
]
}
  • 批量查询(index相同,type相同)
GET  test_index/test_type/_mget
{
"ids": [1,2]
}

mget的重要性

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

案例

1
2
3
4
作者:yust5273链接:https://www.jianshu.com/p/cdfcbe7144ac来源:简书著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69946831/viewspace-3122238/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-09-09

  • 博文量
    2646
  • 访问量
    42125