使用插件自定义文档分数

时间:2019-09-27 15:42:41

标签: elasticsearch

我需要自定义文档分数以进行搜索。问题是我需要为搜索提供参数,并使用第三方库来处理新分数。

用例是如果元素的位置在提供的区域内(geojson作为查询的参数),则提高得分。例如,如果元素在区域#1内,则元素得分将在区域#2的值ab的基础上提高,...

rescore插件是最好的方法吗?参见https://github.com/elastic/elasticsearch/tree/master/plugins/examples/rescore

还有其他方法吗?

我正在使用Elasticsearch 7。

感谢您的帮助! 蒂埃里

2 个答案:

答案 0 :(得分:1)

您是否正在寻找类似

的内容?

映射:

<% if(!currentUser) { %>
// If the user is not logged in
<% } else { %>
// If the user is logged in
<% } %>

查询:在功能评分中,可以为不同的功能添加不同的地理多边形和相应的权重

    "mappings": {
        "properties" : {
            "pin" : {
                "type" : "geo_point"
            }
        }
    }

结果:

{
  "query": {
    "function_score": {
      "query": {
        "match_all": {}
      },
      "functions": [
        {
          "filter": {
            "geo_polygon": {
              "pin": {
                "points": [
                  {
                    "lat": 40,
                    "lon": -70
                  },
                  {
                    "lat": 42,
                    "lon": -74
                  },
                  {
                    "lat": 20,
                    "lon": -90
                  }
                ]
              }
            }
          },
          "weight": 3
        },
        {
          "filter": {
            "geo_polygon": {
              "pin": {
                "points": [
                  {
                    "lat": 10,
                    "lon": -10
                  },
                  {
                    "lat": 12,
                    "lon": -14
                  },
                  {
                    "lat": 5,
                    "lon": -25
                  }
                ]
              }
            }
          },
          "weight": 2
        }
      ]
    }
  }
}

答案 1 :(得分:1)

编写插件可能是解决方案,但是编写插件没有太多文档。

我认为编写插件的主要弊端是使其保持最新状态。您必须为Elasticsearch版本的每次更改(包括次要版本更改)重建您的插件。重建是可以的,但是内部API经常更改,因此简单的更新也可能会导致插件更新。

也许另一种解决方案是使用无痛实现该算法?