我想按 top_hit 的 doc.score 排序桶。我当前的实现如下。
group_by_iid: {
terms: {
field: 'iid',
order: { max_score: 'desc' },
size: 0
},
aggs: {
max_score: { max: { script: 'doc.score' } },
top_hit: {
top_hits: {
sort: [{ source_priority: { order: 'desc' } }],
size: 1
}
}
}
}
这是错误的,因为存储桶是按最高得分排序的,而不是按最高 source_priority 文档的得分排序的。有没有办法解决这个问题?
最佳答案
我有同样的问题,我解决它的方法是在文档分数上引入一个子聚合。然后在我的外部聚合中,我按 max_score 聚合的名称排序。
GET/my-index/my-type/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"searchTerm": {
"query": "style",
"type": "boolean"
}
}
},
{
"flt_field": {
"searchTerm": {
"like_text": "style"
}
}
}
]
}
},
"aggs": {
"group_by_target_url": {
"terms": {
"field": "targetUrl",
"order": {
"max_score": "desc"
}
},
"aggs": {
"max_score": {
"max": {
"script": "_score"
}
}
}
}
}
}
我按照此链接上的说明操作:
关于Elasticsearch 聚合顺序按最高命中分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26213271/