在查询中,我使用inner_hits
返回与查询匹配的嵌套对象列表。
然后,为我的文档的categoryId添加一个聚合,然后为一个热门匹配添加此分类的显示名称。
"aggs": {
"category": {
"terms": {
"field": "categoryId",
"size": 100
},
"aggs": {
"category_value": {
"top_hits": {
"size": 1,
"_source": {
"includes": "categoryName"
}
}
}
}
}
}
现在,当我查看聚合存储桶时,确实获得了仅具有
_source
属性的categoryName
文档,但我还获得了整个inner_hits
集合:{
...
"_source": {
"categoryName": "Armchairs"
},
"inner_hits": {
"my_inner_hits": {
"hits": {
"total": 260,
"max_score": null,
"hits": [{
...
"_source": {
//nested document here
}
}
]
}
}
}
}
有没有办法在
inner_hits
聚合中不包括top_hits
数据?
最佳答案
由于您只需要一个字段,因此我建议您摆脱top_hits
聚合,并使用另一个terms
聚合作为名称:
{
...
"aggs": {
"category": {
"terms": {
"field": "categoryId",
"size": 100
},
"aggs": {
"category_value": {
"terms": {
"field": "categoryName",
"size": 1
}
}
}
}
}
}
这也将更有效率。
更新:
继续使用
terms/top_hits
的另一种方法是利用response filtering并仅返回您需要的内容。例如,将其附加到您的网址将确保您不会在聚合中找到任何内部匹配?filter_path=hits.hits,aggregations.**.key,aggregations.**.doc_count,aggregations.**.hits.hits.hits._source
关于elasticsearch - 使用来源过滤器从热门匹配中排除内部匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57479970/