您需要一个
top_hits汇总。
对于您的具体情况:
{ "query": { "multi_match": { ... } }, "aggs": { "top-uids": { "terms": { "field": "uid" }, "aggs": { "top_uids_hits": { "top_hits": { "sort": [ { "_score": { "order": "desc" } } ], "size": 1 } } } } }}上面的查询会执行您的
multi_match查询并基于汇总结果
uid。对于每个uid存储桶,它仅返回一个结果,但是在存储桶中的所有文档都按照
_score后代顺序排序之后。



