我有一个具有以下映射的索引
{
"mappings": {
"xxxxx": {
"properties": {
"ID": {
"type": "text"
},
"pairs": {
"type": "nested"
},
"xxxxx": {
"type": "text"
}
}
}
}
}
pairs
字段本质上是一个对象数组-每个对象都有一个与之关联的唯一ID
我想做的是从对字段中仅获取一个对象进行更新。在这种程度上,我已经尝试过了
GET /sample/_search/?size=1000
{
"query": {
"bool": {
"must": [
{
"match": {
"ID": "2rXdCf5OM9g1ebPNFdZNqW"
}
},
{
"match": {
"pairs.id": "c1vNGnnQLuk"
}
}
]
}
},
"_source": "pairs"
}
但是,尽管它们是有效的ID,但这只会返回一个空对象。如果删除pairs.id
规则-我将获得整个对象数组。
我需要添加/编辑哪些内容以确保可以同时通过IDS(原始和嵌套)进行查询
答案 0 :(得分:1)
由于pairs
是nested
类型的,因此您需要使用nested
query。另外,您可能还想利用nested inner-hits
:
GET /sample/_search/?size=1000
{
"query": {
"bool": {
"must": [
{
"match": {
"ID": "2rXdCf5OM9g1ebPNFdZNqW"
}
},
{
"nested": {
"path": "pairs",
"query": {
"match": {
"pairs.id": "c1vNGnnQLuk"
}
},
"inner_hits": {}
}
}
]
}
},
"_source": false
}