使用标准分析器我有以下查询
{
"query": {
"match": {
"title": {
"query": "iphone 6",
"operator": "and"
}
}
},
"track_scores": True,
"sort": [
{
"_score": {
"order": "desc"
}
}
],
"size": 10
}
它给了我以下结果' title' => '得分'
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
中的一个作为第一个?
答案 0 :(得分:1)
Got it working using 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
}