gpt4 book ai didi

python - ElasticSearch 匹配查询得分

转载 作者:太空宇宙 更新时间:2023-11-03 17:33:21 28 4
gpt4 key购买 nike

使用标准分析器我有以下查询

{
"query": {
"match": {
"title": {
"query": "iphone 6",
"operator": "and"
}
}
},
"track_scores": True,
"sort": [
{
"_score": {
"order": "desc"
}
}
],
"size": 10
}

这给了我以下结果 'title' => 'score'

iPhone 6 Plus 64GB  => 14.105422
iPhone 6 Plus 128GB => 13.942985
iPhone 6 16GB => 13.678013
iPhone 6 64GB => 13.473294
iPhone 6 Plus 16GB => 12.974828
iPhone 6 128GB => 12.974828

为什么 iPhone 6 PlusiPhone 6 更高?我应该怎样做才能获得其中一台 iPhone 6 作为第一台?

最佳答案

使用 groovy 让它工作

{
"query": {
"function_score": {
"score_mode": "sum",
"boost_mode": "replace",
"query": {
"match": {
"title": {
"query": "iphone 6",
"operator": "and"
}
}
},

"functions": [{
"script_score": {
"script": "def score = 1000 - _source.title.size(); score",
"lang": "groovy"
}
}]
}
},
"track_scores": True,
"sort": [
{
"_score": {
"order": "desc"
}
}
],
"size": 1
}

关于python - ElasticSearch 匹配查询得分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31562351/

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