ES-mget批量查询

作者: yust5273 | 来源:发表于2019-01-19 16:13 被阅读21次

批量查询的好处

  • 减少网络开销:
    一条一条的查,比如说要查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

相关文章

网友评论

    本文标题:ES-mget批量查询

    本文链接:https://www.haomeiwen.com/subject/pvkzdqtx.html