我看到围绕嵌套字段和聚合的一些帖子,但它们似乎都没有回答我的问题。所以,请原谅我,如果这是一个重复的问题,任何帮助将不胜感激。
我们建立了一个讲座索引,讲座具有以下特点:
大致结构如下:
{
"topics": [
{
"id": "TOP1",
"chapters": [
{
"chapterId": 12345,
"availability": [
{
"type": "LIVE",
"lecturer": "Dr. Abraham Fisher",
"lectureChapterId": "861731",
"availableFrom": "2017-09-11 13:00:00",
"expiresAt": "2017-09-11 15:00:00",
"lecturerIds": [
"MON121",
"MEL122"
]
},
{
"type": "LIVE",
"lecturer": "Dr. Bob Fisher",
"lectureChapterId": "181751",
"availableFrom": "2017-09-11 20:00:00",
"expiresAt": "2017-09-11 22:00:00",
"lecturerIds": [
"MON122",
"MEL123"
]
},
{
"type": "LIVE",
"lecturer": "Dr. Bob Fisher",
"lectureChapterId": "181751",
"availableFrom": "2017-09-17 20:00:00",
"expiresAt": "2017-09-17 22:00:00",
"lecturerIds": [
"MON122",
"MEL123"
]
},
{
"type": "LIVE",
"lecturer": "Dr. Abraham Fisher",
"lectureChapterId": "861731",
"availableFrom": "2017-09-17 13:00:00",
"expiresAt": "2017-09-17 15:00:00",
"lecturerIds": [
"MON121",
"MEL122"
]
},
{
"type": "ONLINE",
"quality" : "HD",
"price" : 19.99,
"lecturer": "Dr. Catherine Fisher",
"lectureChapterId": "9127312",
"availableFrom": "2017-01-17 00:00:00",
"expiresAt": "2017-12-31 23:59:59",
"lecturerIds": [
"MON120",
"MEL120"
]
},
{
"type": "ONLINE",
"quality" : "SD",
"price" : 10.99,
"lecturer": "Dr. Catherine Fisher",
"lectureChapterId": "9127312",
"availableFrom": "2017-01-17 00:00:00",
"expiresAt": "2017-12-31 23:59:59",
"lecturerIds": [
"MON120",
"MEL120"
]
}
]
}
]
}
]
}
现在,如果要求只返回按章节分组的第一个详细讲座,LIVE讲座讲师并返回所有在线讲座(以及讲座主题的其他元数据),那么最好的方法是什么?在上面的例子中,应该返回Abraham Fisher博士和Bob Fisher博士9月11日的讲座。
我尝试使用inner_hits,但显然,它不允许聚合(我收到以下错误)。
"[nested] query does not support [aggs]"
P.S:汇总需要在章级而不是讲座主题(根)级别。
答案 0 :(得分:1)
你可以发帖吗?对于嵌套字段的聚合,您始终需要指定嵌套路径。见https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html
我不知道您的完整数据模型,但是如果您可以控制文档结构并且只需要它进行搜索,那么您可以尝试通过非规范化将其展平一些。