elasticsearch - 术语聚合返回多个字段 (min_doc_count: 0)
问题描述
我正在进行术语聚合,但我想返回多个字段。我希望用户通过“slug”(我的名字)选择存储桶,但显示实际的“名字”(我的名字)。
此刻,我正在制作这样的TopHits SubAggregation:
"organisation": {
"aggregations": {
"label": {
"top_hits": {
"_source": {
"includes": [
"organisations.name"
]
},
"size": 1
}
}
},
"terms": {
"field": "organisations.slug",
"min_doc_count": 0,
"size": 20
}
}
当我的整个查询实际上找到一些存储桶/结果时,这会给出所需的结果。
你看我已经设置了min_doc_count
to 0
which 将返回文档计数为 0 的存储桶。我在这里面临的问题是我的 TopHits 响应是空的,这导致无法向客户端呈现正确的名称。
示例响应:
"organisation": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "my-name",
"doc_count": 27,
"label": {
"hits": {
"total": 27,
"max_score": 1,
"hits": [
{
"_index": "users",
"_type": "doc",
"_id": "4475",
"_score": 1,
"_source": {
"organisations": [
{
"name": "My name"
}]
}
}]
}
}
},
{
"key": "my-name-2",
"doc_count": 0,
"label": {
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
},
.....
有人实现了这个预期的结果吗?我觉得 TopHits 在这里帮不了我。它应该始终获取名称。
我也尝试过:
- 使用术语子聚合。(同样的结果)
- 使用重要的术语子聚合。(同样的结果)
我认为可能是一个解决方案,但感觉很脏:
organisations.slug
用“ ___ ”索引一个新字段organisations.name
并通过它来发挥魔力。- 手动查询count为0的name字段(读取TopHits为空)
亲切的问候,在此先感谢
解决方案
推荐阅读
- reporting-services - SSRS 无法识别 .NET Framework 类库
- angular - NgRx Action Payload 没有达到效果 - 没有错误
- curl - 在颤动中使用 Dio 的 POST 问题
- apache-spark - 分布式规则引擎
- scala - 如何将具有 Decimal 的 spark DataFrame 转换为具有相同精度的 BigDecimal 的 Dataset?
- c# - 行可见性datagridview c#
- ios - 如何在 EXPO 中重建 iOS?
- javascript - 页脚链接在移动视图上消失
- django - TypeError:在 Django 数据迁移期间,Decimal 类型的对象不是 JSON 可序列化的
- python - 为什么这么多 Python 库是用 C/C++ 编写的