我找到了一種方法。
"aggregatePerEmployee" : {
"terms" : {
"field" : "employee.raw",
"order": {
"top_hit": "desc"
},
"size" : 4
},
"aggs": {
"top_hit" : {
"max": {
"script": "_score"
}
}
}
}
通過這種方式,聚合訂單考慮每位員工的最高分數。
查看結果
"aggregatePerEmployee": {
"doc_count_error_upper_bound": -1,
"sum_other_doc_count": 1145,
"buckets": [
{
"key": "Michael Seam Carl",
"doc_count": 3,
"top_hit": {
"value": 2.097010612487793
}
},
{
"key": "Michael Seam Porter ",
"doc_count": 1,
"top_hit": {
"value": 2.0433993339538574
}
},
{
"key": "Lucas",
"doc_count": 30,
"top_hit": {
"value": 2.0033993339538574
}
},
{
"key": "Jose White ",
"doc_count": 15,
"top_hit": {
"value": 1.5995635986328125
}
}
]
}
PS:啓用此Groovy腳本,需要編輯elasticsearch.yml,並把它這一行:
script.engine.groovy.inline.aggs: on
後,重新啓動elasticsearch節點