gpt4 book ai didi

elasticsearch - Elasticsearch聚合最大值

转载 作者:行者123 更新时间:2023-12-03 01:52:14 24 4
gpt4 key购买 nike

{
"aggs":{
"nest_exams":{
"nested":{
"path": "exams"
},
"aggs":{
"exams":{
"filter" : {
"term": {
"exams.exam_id": 96690
}
},
"aggs":{
"nested_attempts":{
"nested":{
"path": "exams.attempts"
},
"aggs":{
"user_attempts":{
"terms":{
"field": "exams.attempts.user_id",
"size": 0
},
"aggs":{
"max_score":{
"max":{
"field": "exams.attempts.order_score"
}
}
}
}
}
}
}
}
}
}
}

您好,我有这个汇总查询。问题是,即使我可以找到每个用户的max_score,也无法将其汇总到最大聚合器中以找到最佳分数的日期。

尝试具有user_id,order_score,date_start

最佳答案

一种替代方法是不运行max度量标准子聚合,而是使用top_hits而不是按降序max_score排序,以便您可以检索该文档的date_start:

{
"aggs": {
"nest_exams": {
"nested": {
"path": "exams"
},
"aggs": {
"exams": {
"filter": {
"term": {
"exams.exam_id": 96690
}
},
"aggs": {
"nested_attempts": {
"nested": {
"path": "exams.attempts"
},
"aggs": {
"user_attempts": {
"terms": {
"field": "exams.attempts.user_id",
"size": 0
},
"aggs": {
"max_score": {
"top_hits": {
"sort": {
"exams.attempts.order_score": "desc"
},
"size": 1,
"_source": [
"date_start"
]
}
}
}
}
}
}
}
}
}
}
}
}

关于elasticsearch - Elasticsearch聚合最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39369306/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com