使用标准分析器我有以下查询
{
"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 Plus
比 iPhone 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/