Multi GET API允许基于索引,类型(可选)和id(以及可能的路由)获取多个文档。响应包括一个
docs
数组,其中所有获取的文档按顺序对应于原始的多重获取请求(如果特定获取失败,则包含此错误的对象将包含在响应中)。成功获取的结构在结构上类似于
get
API 提供的文档。
GET / _mget
{
“docs”:[
{
“ _ index ”:“test”,
“_ type”:“_ doc”,
“ _ id ”:“1”
},
{
“ _ index”:“test”,
“_ type”:“_ doc” “,
”_ id“:”2“
}
]
}
针对索引
GET /test/_mget
{
"docs" : [
{
"_type" : "_doc",
"_id" : "1"
},
{
"_type" : "_doc",
"_id" : "2"
}
]
}针对类型
GET /test/type/_mget
{
"docs" : [
{
"_id" : "1"
},
{
"_id" : "2"
}
]
}
在这种情况下,该ids元素可以直接用于简化请求:
GET / test / type / _mget
{
“ids”:[“1”,“2”]
}
源过滤
默认情况下,将为每个文档返回(如果有存储)源字段。与GET API类似,您可以通过使用源代码参数只检索部分源(或者根本不检索)。您还可以使用URL参数_source,_source_include及_source_exclude指定默认值,默认值将在没有文档指令时使用。
GET /_mget
{
"docs" : [
{
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"_source" : false
},
{
"_index" : "test",
"_type" : "_doc",
"_id" : "2",
"_source" : ["field3", "field4"]
},
{
"_index" : "test",
"_type" : "_doc",
"_id" : "3",
"_source" : {
"include": ["user"],
"exclude": ["user.location"]
}
}
]
}
字段
GET /_mget
{
"docs" : [
{
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"stored_fields" : ["field1", "field2"]
},
{
"_index" : "test",
"_type" : "_doc",
"_id" : "2",
"stored_fields" : ["field3", "field4"]
}
]
}
或者,您可以
stored_fields
将查询字符串中的参数指定为默认值,以应用于所有文档。
GET /test/type/_mget?stored_fields=field1,field2
{
"docs" : [
{
"_id" : "1"
},
{
"_id" : "2",
"stored_fields" : ["field3", "field4"]
}
]
}
id为1的文档返回 field1,field2;
id为2 的文档返回field3,field4.
路由
您还可以将路由值指定为参数:
GET /_mget?routing=key1
{
"docs" : [
{
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"routing" : "key2"
},
{
"_index" : "test",
"_type" : "_doc",
"_id" : "2"
}
]
}
在此示例中,
test/type/2
将从与路由密钥对应的分片中获取
key1
文档,但是
test/type/1
将从与路由密钥对应的分片中获取文档
key2
。
MultiGET API支持通过索引、类型(可选)和ID获取多个文档。响应包含一个docs数组,对应原始请求中的文档。支持简化请求、源过滤、特定字段检索及路由设置。
992

被折叠的 条评论
为什么被折叠?



