elasticsearch学习笔记(十六)——Elasticsearch mget批量查询api实战

栏目: 后端 · 发布时间: 7年前

内容简介:首先说明一下为什么需要批量查询操作?假设一下比如说我们没有批量查询的操作,那么当我们获取数据的时候,就是一条一条的查询。设想一下我们要获取100条数据,那么就要发送100次请求,这个开销时很大的。但是有了批量查询的话,查询100条数据,就只需要发送一次网络请求就可以了,网络请求的性能开销缩减100倍。下面是实战部分,演示一下一条一条查询与批量查询:

首先说明一下为什么需要批量查询操作?

假设一下比如说我们没有批量查询的操作,那么当我们获取数据的时候,就是一条一条的查询。设想一下我们要获取100条数据,那么就要发送100次请求,这个开销时很大的。但是有了批量查询的话,查询100条数据,就只需要发送一次网络请求就可以了,网络请求的性能开销缩减100倍。

下面是实战部分,演示一下一条一条查询与批量查询:

(1)一条一条查询

GET /test_index/_doc/1
{
  "_index" : "test_index",
  "_type" : "_doc",
  "_id" : "1",
  "_version" : 8,
  "_seq_no" : 7,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "test_field" : "test test",
    "name" : "test1"
  }
}
GET /test_index/_doc/2
{
  "_index" : "test_index",
  "_type" : "_doc",
  "_id" : "2",
  "_version" : 4,
  "_seq_no" : 3,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "test_field" : "test client 1",
    "name" : "test1"
  }
}

(2)mget批量查询

GET /_mget
{
  "docs": [
    {
      "_index": "test_index",
      "_id": 1
    },
    {
      "_index": "test_index",
      "_id": 2
    }
  ]
}
{
  "docs" : [
    {
      "_index" : "test_index",
      "_type" : "_doc",
      "_id" : "1",
      "_version" : 8,
      "_seq_no" : 7,
      "_primary_term" : 1,
      "found" : true,
      "_source" : {
        "test_field" : "test test",
        "name" : "test1"
      }
    },
    {
      "_index" : "test_index",
      "_type" : "_doc",
      "_id" : "2",
      "_version" : 4,
      "_seq_no" : 3,
      "_primary_term" : 1,
      "found" : true,
      "_source" : {
        "test_field" : "test client 1",
        "name" : "test1"
      }
    }
  ]
}

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

DOM Scripting

DOM Scripting

Jeremy Keith / friendsofED / 2010-12 / GBP 27.50

There are three main technologies married together to create usable, standards-compliant web designs: XHTML for data structure, Cascading Style Sheets for styling your data, and JavaScript for adding ......一起来看看 《DOM Scripting》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具