当我在 elasticsearch 上进行搜索时,我想操纵我得到的分数。我已经使用了 boost 选项,但它并没有给我想要的结果。经过一番阅读,我认为 function_score 查询是我的问题的解决方案。我了解它是如何工作的,但我不知道如何更改当前查询以将其与 function_score 查询一起使用。
"query": {
"filtered": {
"query": {
"bool": {
"should": [{
"multi_match": {
"type": "most_fields",
"query": "paus",
"operator": "and",
"boost": 2,
"fields": [
"fullname^2",
"fullname.folded",
"alias^2",
"name^2"
],
"fuzziness": 0
}
}, {
"multi_match": {
"type": "most_fields",
"query": "paus",
"operator": "and",
"boost": 1.9,
"fields": [
"taggings.tag.name^1.9",
"function",
"relations.master.name^1.9",
"relations.master.first_name^1.9",
"relations.master.last_name^1.9",
"relations.slave.name^1.9",
"relations.slave.first_name^1.9",
"relations.slave.last_name^1.9"
],
"fuzziness": 0
}
}, {
"multi_match": {
"type": "most_fields",
"query": "paus",
"operator": "and",
"fields": [
"fullname",
"alias",
"name"
],
"boost": 0.2,
"fuzziness": 1
}
}, {
"match": {
"extra": {
"query": "paus",
"fuzziness": 0,
"boost": 0.1
}
}
}]
}
},
"filter": {
"bool": {
"must": [
{
"terms": {
"type": ["Person"]
}
},
{
"term": {
"deleted": false
}
}
]
}
}
}
如您所见,我们有四种匹配项。
- Boost 2:当名称完全匹配时
- Boost 1.9:当标签上有完全匹配时
- Boost 0.2:当名称匹配但一个字符写错时
- Boost 0.1:当额外(描述)字段中有匹配项时
我面临的问题是一个字符写错并且没有标记得分高于正确标记和整个单词写错的匹配。那应该是另一种方式...
任何帮助,将不胜感激 :)