mget批量查询

  1. 批量查询的好处
    就是一条一条的查询,比如说要查询100条数据,那么就要发送100次网络请求,这个开销还是很大的
    如果进行批量查询的话,查询100条数据,就只要发送1次网络请求,网络请求的性能开销缩减100倍
  2. mget批量查询的语法
    GET _mget
    {
      "docs":[
        {
          "_index":"test_index",
          "_type":"test_type",
          "_id":1
        },
        {
          "_index":"test_index",
          "_type":"test_type",
          "_id":2
        }
        ]
    }
    {
      "took": 2,
      "timed_out": false,
      "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
      },
      "hits": {
        "total": 9,
        "max_score": 1,
        "hits": [
          {
            "_index": "test_index",
            "_type": "test_type",
            "_id": "AWypxxLYFCl_S-ox4wvd",
            "_score": 1,
            "_source": {
              "test_content": "my test"
            }
          },
          {
            "_index": "test_index",
            "_type": "test_type",
            "_id": "8",
            "_score": 1,
            "_source": {
              "test_field": "test client 2"
            }
          },
          {
            "_index": "test_index",
            "_type": "test_type",
            "_id": "10",
            "_score": 1,
            "_source": {
              "test_field1": "test1",
              "test_field2": "updated test2"
            }
          },
          {
            "_index": "test_index",
            "_type": "test_type",
            "_id": "2",
            "_score": 1,
            "_source": {
              "test_content": "my test"
            }
          },
          {
            "_index": "test_index",
            "_type": "test_type",
            "_id": "4",
            "_score": 1,
            "_source": {
              "test_field": "test test"
            }
          },
          {
            "_index": "test_index",
            "_type": "test_type",
            "_id": "6",
            "_score": 1,
            "_source": {
              "test_field": "test test"
            }
          },
          {
            "_index": "test_index",
            "_type": "test_type",
            "_id": "1",
            "_score": 1,
            "_source": {
              "test_field1": "test field1",
              "test_field2": "test field2"
            }
          },
          {
            "_index": "test_index",
            "_type": "test_type",
            "_id": "7",
            "_score": 1,
            "_source": {
              "test_field": "test client 1"
            }
          },
          {
            "_index": "test_index",
            "_type": "test_type",
            "_id": "11",
            "_score": 1,
            "_source": {
              "num": 0,
              "tags": []
            }
          }
        ]
      }
    }
    View Code

相关文章: