zoukankan      html  css  js  c++  java
  • (08)ElasticSearch 批量获取文档MultiGet

      使用Multi Get 可以通过索引名、类型名、文档id一次得到一个文档集合,文档可以来自同一个索引库,也可以来自不同索引库。

      1、准备数据

    PUT /lib/user/1
    {
        "first_name":"Jane1",
        "last_name":"Smith1",
        "age":31,
        "about":"I like to collect rock albums1",
        "interests":[ "music1" ]
    }
    
    PUT /lib/user/2
    {
        "first_name":"Jane2",
        "last_name":"Smith2",
        "age":32,
        "about":"I like to collect rock albums2",
        "interests":[ "music2" ]
    }
    
    PUT /lib/user/3
    {
        "first_name":"Jane3",
        "last_name":"Smith3",
        "age":33,
        "about":"I like to collect rock albums1",
        "interests":[ "music3" ]
    }
    
    PUT /lib2/user2/1
    {
        "first_name":"Jane1",
        "last_name":"Smith1",
        "age":31,
        "about":"I like to collect rock albums1",
        "interests":[ "music1" ]
    }
    
    PUT /lib2/user2/2
    {
        "first_name":"Jane2",
        "last_name":"Smith2",
        "age":32,
        "about":"I like to collect rock albums2",
        "interests":[ "music2" ]
    }
    
    PUT /lib2/user2/3
    {
        "first_name":"Jane3",
        "last_name":"Smith3",
        "age":31,
        "about":"I like to collect rock albums3",
        "interests":[ "music3" ]
    }

      2、操作演示

      同时查询到文档id是1、2、3的文档。会查出6条数据

    GET /_mget
      {
          "docs":[
             {
                  "_index":"lib",
                  "_type":"user",
                  "_id":1
              },
              {
                 "_index":"lib",
                 "_type":"user",
                 "_id":2
             },
             {
                 "_index":"lib",
                 "_type":"user",
                 "_id":3
             },
              {
                  "_index":"lib2",
                  "_type":"user2",
                  "_id":1
              },
              {
                 "_index":"lib2",
                 "_type":"user2",
                 "_id":2
             },
             {
                 "_index":"lib2",
                 "_type":"user2",
                 "_id":3
             }
         ]
     }

      指定每个文档显示的字段:

    GET /_mget
    {
        "docs":[
            {
                  "_index":"lib",
                  "_type":"user",
                  "_id":1,
                  "_source":"interests"
              },
             {
                 "_index":"lib",
                 "_type":"user",
                 "_id":2,
                 "_source":["age","interests"]
             }
         ]
    }

      批量获取文档的简单写法有以下两种

    GET /lib/user/_mget
      {
        "docs":[
            {
                "_id":1
            },
            {
                "_id":2
            }
        ]
    }
    GET /lib/user/_mget
    {
        "ids":["1","2"]
    }
  • 相关阅读:
    hibernate框架的搭建与简单实现增删改
    $.ajax();详解
    利用json实现数据传输
    利用ajax实现数据传输
    错误:Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp;的解决
    简单使用jstl实现敏感字替换
    实用jstl实现未登录时不能绕过登录界面的效果
    简单实用jstl实现“登录|注册”
    简单实用jstl实现代码编写
    简单使用EL进行标签的替换
  • 原文地址:https://www.cnblogs.com/javasl/p/11405356.html
Copyright © 2011-2022 走看看