25、深度探秘搜索技术之四种常见的相关度分数优化方法
query-time boost
GET /forum/_search { "query":{ "bool":{ "should":[ { "match":{ "title":{ "query":"java spark", "boost":2 } } }, { "match":{ "content":"java spark" } } ] } } }
negative boost
GET /forum/_search
{
"query":{
"bool":{
"must":[
{
"match":{
"content":"java"
}
}
],
"must_not": [
{
"match":{
"content":"spark"
}
}
]
}
}
}
- 搜索包含java,尽量不包含spark的doc,如果包含了spark,不会说排除掉这个doc,而是说将这个doc的分数降低,包含了negative term的doc,分数乘以negative boost,分数降低
GET /forum/_search { "query":{ "boosting": { "positive":{ "match":{ "content":"java" } }, "negative": { "match":{ "content": "spark" } }, "negative_boost": 0.2 } } }
constant_score
不需要相关度评分,直接走constant_score加filter,所有的doc分数都是1
GET /forum/_search { "query":{ "constant_score": { "filter": { "bool": { "should":[ { "term":{ "title":"java" } }, { "term":{ "title":"spark" } } ] } } } } }
立志如山 静心求实
浙公网安备 33010602011771号