zoukankan      html  css  js  c++  java
  • 26.mget批量查询

    主要知识点

       

    一、mget批量查询的好处

       

    get查询就是一条一条的查询,比如说要查询100条数据,那么就要发送100次网络请求,这个开销还是很大的。如果使用mget进行批量查询的话,查询100条数据,就只要发送1次网络请求,网络请求的性能开销缩减100倍,这样可以更好的优化性能。

    二、mget的语法

    GET /_mget

    {

    "docs" : [{json1},{json2},……]

    }

    三、用法举例

    1、先准备两条数据

    PUT /test_index/test_type/1

    {

    "test_field1": "test field1"

    }

    PUT /test_index/test_type/2

    {

    "test_field2": "test field2"

    }

    2、用get一条一条的查询

    GET /test_index/test_type/1

    GET /test_index/test_type/2

    可以看到,要查询两条数据,必须发送两次请求。

    3mget批量查询:_index,_type,_id都不相同

    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": 1,

    "found": true,

    "_source": {

    "test_field1": "test field1"

    }

    },

    {

    "_index": "test_index",

    "_type": "test_type",

    "_id": "2",

    "_version": 1,

    "found": true,

    "_source": {

    "test_field2": "test field2"

    }

    }

    ]

    }

       

    4mget批量查询:_index相同,_type,_id不相同

    GET /test_index/_mget

    {

    "docs" : [

    {

    "_type" : "test_type",

    "_id" : 1

    },

    {

    "_type" : "test_type",

    "_id" : 2

    }

    ]

    }

    查询结果同上

    5mget批量查询:_index_type相同,_id不相同

    GET /test_index/test_type/_mget

    {

    "ids": [1, 2]

    }

    查询结果同上

    四、mget的重要性

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

  • 相关阅读:
    将make的输出重定向到文件
    ubuntu mount u盘以及cp拷贝文件夹
    Emacs Tutorial摘录
    c#实现每隔一段时间执行代码(多线程)
    socket.BeginReceiveFrom异步接收信息时,回调函数无法正常进入
    23个C#实用技巧
    C#中实现Form的透明属性变化即渐隐效果
    C#键位定制:设置一个文本框只能输入数字键
    byte 与 bit 的转换
    C# Socket UDP 案例 2
  • 原文地址:https://www.cnblogs.com/liuqianli/p/8463967.html
Copyright © 2011-2022 走看看