ElasticSearch:相关性得分由function_score覆盖

时间:2015-03-12 08:36:12

标签: php elasticsearch

以下是我的弹性搜索查询,我使用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"
          }
        }
      ]
    }
  }
}

1 个答案:

答案 0 :(得分:0)

是的,这是"正常",script_score将覆盖以前的分数。

您可以在脚本中使用_score变量来使用它。

(例如"script": "_score * (0.08 / ((3.16*pow(10,-11)) * abs(1426072330 - doc[\"reviews.created_time\"].value) + 0.05)) + 1.0"

相关问题