• (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"]
    }
  • 相关阅读:
    python3.6 range() 函数
    常见文件头,文件尾总结。
    pycharm多行代码注释,或取消。
    php设计模式之命令模式
    php设计模式之工厂模式
    php设计模式之观察者模式
    SQLServer导出sql文件,导出表架构和数据
    vs2012建设网站,IIS8发布
    Subsonic 配置文件
    去掉txt中的重复标题
  • 原文地址:https://www.cnblogs.com/javasl/p/11405356.html
Copyright © 2020-2023  润新知