ElasticSearch学习

文章40 |   阅读 18970 |   点赞0

来源:https://blog.csdn.net/ywl470812087/category_9621251.html

Multi GET API介绍

x33g5p2x  于2021-12-19 转载在 其他  
字(2.7k)|赞(0)|评价(0)|浏览(338)

#先添加几个文档

PUT /lib/user/1
{
  "first_name":"Jane",
  "last_name":"Smith",
  "age":36,
  "about":"I like to collect rock albums",
  "interests":["music"]
}

PUT /lib/user/2
{
  "first_name":"Jane",
  "last_name":"tom",
  "age":38,
  "about":"I like to collect rock albums",
  "interests":["music"]
}

获取

#批量获取文档 Multi GET API
GET /_mget
{
  "docs":[
      {"_index":"lib",
      "_type":"user",
      "_id":1
      },
      {
      "_index":"lib",
      "_type":"user",
      "_id":2
      },
      {
      "_index":"lib",
      "_type":"user",
      "_id":3
      }
      
    ]
  
}

返回信息:

{
  "docs" : [
    {
      "_index" : "lib",
      "_type" : "user",
      "_id" : "1",
      "_version" : 1,
      "_seq_no" : 7,
      "_primary_term" : 1,
      "found" : true,
      "_source" : {
        "first_name" : "Jane",
        "last_name" : "Smith",
        "age" : 36,
        "about" : "I like to collect rock albums",
        "interests" : [
          "music"
        ]
      }
    },
    {
      "_index" : "lib",
      "_type" : "user",
      "_id" : "2",
      "_version" : 1,
      "_seq_no" : 3,
      "_primary_term" : 1,
      "found" : true,
      "_source" : {
        "first_name" : "Jane",
        "last_name" : "tom",
        "age" : 38,
        "about" : "I like to collect rock albums",
        "interests" : [
          "music"
        ]
      }
    },
    {
      "_index" : "lib",
      "_type" : "user",
      "_id" : "3",
      "found" : false
    }
  ]
}

文档id=1和文档id=2返回true  文档id=3的返回false 因为文档3没有添加

获取文档指定的字段

#获取指定字段
GET /_mget
{
  "docs":[
      {"_index":"lib",
      "_type":"user",
      "_id":1,
      "_source": "interests"
      },
      {
      "_index":"lib",
      "_type":"user",
      "_id":2,
      "_source":["interests","age"]
      }
    ]
  
}

获取结果:

{
  "docs" : [
    {
      "_index" : "lib",
      "_type" : "user",
      "_id" : "1",
      "_version" : 1,
      "_seq_no" : 7,
      "_primary_term" : 1,
      "found" : true,
      "_source" : {
        "interests" : [
          "music"
        ]
      }
    },
    {
      "_index" : "lib",
      "_type" : "user",
      "_id" : "2",
      "_version" : 1,
      "_seq_no" : 3,
      "_primary_term" : 1,
      "found" : true,
      "_source" : {
        "interests" : [
          "music"
        ],
        "age" : 38
      }
    }
  ]
}

相关文章