gpt4 book ai didi

Elasticsearch 聚合顺序按最高命中分数

转载 作者:行者123 更新时间:2023-11-29 02:44:40 25 4
gpt4 key购买 nike

我想按 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"
}
}
}
}
}
}

我按照此链接上的说明操作:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html

关于Elasticsearch 聚合顺序按最高命中分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26213271/

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