Elasticsearch Aggregation Max Value -
{ "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" } } } } } } } } } } }
hello, have aggregation query. problem can found max_score per user, can't sub aggregate max aggregator find date of best score.
an attempt have user_id,order_score,date_start
an alternative not run max
metric sub-aggregation, top_hits
instead sorted descending max_score
can retrieve date_start
of document:
{ "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" ] } } } } } } } } } } } }
Comments
Post a Comment