# 使用function score解决排序模型
# tf-idf 打分和function score 做融合
GET shop/_search
{
"_source": "*",
"script_fields": {
"distance": {
"script": {
"source": "haversin(lat,lon,doc['location'].lat,doc['location'].lon)",
"lang":"expression",
"params": {"lat":31.23916171,"lon":121.48780049}
}
}
},
"query": {
"function_score": {
"query": {
"bool": {
"must": [
{
"match": {
"name": {"query": "凯悦","boost": 0.1}
}
},{
"term":
{ "seller_disabled_flag": 0} // 表明商家没有被禁用
}
]
}
},
"functions": [ // 定义排序规则
{
"gauss": { // 高斯衰减函数打分
"location": {
"origin": "31.23916171,121.48780049",
"scale": "100km",
"offset": "0km", // 起始点
"decay": 0.5
}
},
"weight": 9 // 相对于评分 距离是主要因素
},{
"field_value_factor": {
"field": "remark_score" // 评分
},
"weight": 0.2
}
,{
"field_value_factor": { // 商家的评分以5分为归一化
"field": "seller_remark_score"
},
"weight": 0.1
}
],
"score_mode": "sum",
"boost_mode": "sum" // 和对应的query 的打分规则 改为 文本相关性不考虑 基于距离和评分
}
}
, "sort": [
{
"_score": {
"order": "desc"
}
}
]
}
处理了距离字段
处理了召回规则
衰减函数分为如下三类: