是否可以通過在Elasticsearch查詢中搜索子文檔來返回父數據?從Elasticsearch返回子數據文件的父數據
我有兩種文檔類型,例如書和章,與父/子(不嵌套)相關。
我想在子文檔上運行搜索並返回子文檔,其中包含父文檔的一些字段。我試圖避免對父進行單獨的查詢。
更新
唯一可行的辦法,我能找到的是使用has_child
查詢,然後一個系列片集合的鑽回孩子,然後再次申請查詢/過濾器。但是,這看起來過於複雜和低效。
GET index/_search
{
"size": 10,
"query": {
"has_child": {
"type": "chapter",
"query": {
"term": {
"field": "value"
}
}
}
},
"aggs": {
"name1": {
"terms": {
"size": 50,
"field": "id"
},
"aggs": {
"name2": {
"top_hits": {
"size": 50
}
},
"name3": {
"children": {
"type": "type2"
},
"aggs": {
"docFilter": {
"filter": {
"query": {
"match": {
"_all": "value"
}
}
},
"aggs": {
"docs": {
"top_hits": {
"size": 50
}
}
}
}
}
}
}
}
}
}
你需要更具體。爲「嵌套」查詢返回的文檔確實包含「根」文檔中的字段。 – 2015-02-11 10:39:37
我已經更新了原始問題和更多信息。 – 2015-02-11 10:44:18
我想知道如果你找到答案。我正在查找完全相同的查詢。 – batmaci 2016-01-22 09:37:26