以下是我的弹性搜索查询,我正在使用function_score
按以下方式对结果进行排序:
1.第一个查询应与某些字段匹配(全文搜索)
2. 根据用户当前位置的订单结果(使用高斯函数)
3.对那些有建议的服务提供者给予更多的权重(使用高斯函数)
4. 优先考虑最近经过审核的服务提供商(使用脚本分数)
现在 (2,3,4) 点排序将在结果集上完成,但问题是每当我使用地理位置功能完全匹配的服务提供商重新排序并在列表中向下时,我的查询显示结果接近用户位置,无论它与其他文档的匹配度较低。
以下是我的查询,请帮我解决这个问题。还请建议优化我的这个场景,这是解决这个问题的最佳方法。
{
"from": 0,
"size": 15,
"sort": {
"_score": {
"order": "desc"
}
},
"query": {
"function_score": {
"query": {
"bool": {
"must": [
{
"term": {
"status": "1"
}
},
{
"query_string": {
"default_field": "_all",
"query": "Parag Gadhia Parenting classes",
"fields": [
"service_prrovider_name^3",
"location^2",
"category_name^5",
"keyword"
],
"use_dis_max": true
}
},
{
"term": {
"city_id": "1"
}
}
],
"should": [
{
"term": {
"category.category_name": "parenting classes"
}
}
]
}
},
"functions": [
{
"gauss": {
"geo_location": {
"origin": {
"lat": "19.451624199999998",
"lon": "72.7966481"
},
"offset": "20km",
"scale": "3km"
}
}
},
{
"gauss": {
"likes_count": {
"origin": 3,
"offset": "5",
"scale": "20"
}
},
"weight": 2
},
{
"script_score": {
"script": "(0.08 / ((3.16*pow(10,-11)) * abs(1426072330 - doc['"reviews.created_time'"].value) + 0.05)) + 1.0"
}
}
]
}
}
}
是的,这是"正常的",script_score将覆盖之前的分数。
您可以在脚本中使用_score
变量来使用它。
(如"script": "_score * (0.08 / ((3.16*pow(10,-11)) * abs(1426072330 - doc['"reviews.created_time'"].value) + 0.05)) + 1.0"
)