文章40 | 阅读 24277 | 点赞0
#先添加几个文档
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
}
}
]
}
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/ywl470812087/article/details/104807240
内容来源于网络,如有侵权,请联系作者删除!