如果我有一个搜索短语的查询,我如何让Elasticsearch根据短语中每个单词的顺序和距离而不是它们的存在来对分数进行加权?例如,如果我搜索“房屋出租”,则会构建查询:
{
"query": {
"bool": {
"must": [{
"query_string": {
"query": "house for rent"
}
}]
}
}
}
此查询返回的结果按如下顺序排序:
"I am looking to rent a house" -> all terms present out of order with words in between
"I am looking for a house that would be for me to rent" -> all terms present in order with words in between
"I am looking for house to rent" -> 'house for rent' exactly
"I live in a house" -> only 1 term present
前3个结果中包含该短语中的所有单词,但有时会出现乱序或中间包含单词的情况。我希望确切的词组匹配得分最高,但事实并非如此。如何调整评分以考虑词组的顺序和距离?我可以使用query_string
来实现还是要使用其他类型的查询?