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"]
    }
  • 相关阅读:
    五分钟秒懂机器学习混淆矩阵、ROC和AUC
    五分钟学会Python装饰器,看完面试不再慌
    LeetCode54 螺旋矩阵,题目不重要,重要的是这个技巧
    Golang——变量的声明与定义
    LeetCode52题,别再问我N皇后问题了
    spark中的pair rdd,看这一篇就够了
    MySQL不香吗,为什么还要有noSQL?
    JBOSS安装配置详细教程
    Aspose.Words关于域的应用
    SqlServer PIVOT行转列
  • 原文地址:https://www.cnblogs.com/javasl/p/11405356.html
Copyright © 2011-2022 走看看