【发布时间】:2020-10-29 08:35:29
【问题描述】:
假设我在 Elasticsearch 中有这些文档:
{
"display_name": "Jose Cummings",
"username": "josecummings"
},
{
"display_name": "Jose Ramirez",
"username": "elite_gamer"
},
{
"display_name": "Lance Abrams",
"username": "abrams1"
},
{
"display_name": "Steve Smith",
"username": "josesmose"
}
我想针对display_name 和username 字段运行“键入时”搜索Jose,我可以这样做:
{
"query": {
"bool": {
"must": {
"multi_match": {
"fields": [
"display_name",
"username"
],
"query": "Jose",
"type": "bool_prefix",
"fuzziness": "AUTO",
"boost": 50
}
}
}
}
}
这里的问题是,当我搜索Jose 时,Jose Cummings 得到 100 分,而 Jose Ramirez 和 Steve Smith 只得到 50 分,因为这似乎是两个字段的得分相加。这实质上是奖励拥有与username 相同的display_name 的用户,这是我们不希望发生的。
有没有办法只从两个字段中获取最高分数?我现在使用function_score、boost_mode/score_mode、constant_score 尝试了几十种不同的组合,尝试使用多个match_bool_prefix 查询等进行should 匹配。我没有尝试过似乎实现这一目标。
【问题讨论】: