使用插件自定义文档分数



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

用例是在元素的位置在提供的区域内(geojson 作为查询的参数(时提高分数。例如,如果元素位于区域 #1 内,则元素分数会通过值a和区域 #2 的b提升,...

重新评分插件是最好的方法吗?请参阅 https://github.com/elastic/elasticsearch/tree/master/plugins/examples/rescore。

还有其他方法吗?

我正在使用 Elasticsearch 7。

感谢您的帮助! 蒂埃里

您是否正在寻找如下所示的内容

映射:

"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
}
]
}
}
}

结果:

[
{
"_index" : "location",
"_type" : "_doc",
"_id" : "rhn8f20BIb7c4jbYhr3Z",
"_score" : 3.0,
"_source" : {
"pin" : {
"lat" : 40.73,
"lon" : -74.1
}
}
},
{
"_index" : "location",
"_type" : "_doc",
"_id" : "rxn8f20BIb7c4jbYz709",
"_score" : 3.0,     ---> score same as assigned weight
"_source" : {
"pin" : {
"lat" : 40.717,
"lon" : -73.99
}
}
},
{
"_index" : "location",
"_type" : "_doc",
"_id" : "CI25gG0BsKuS2MwMKcVU",
"_score" : 2.0,
"_source" : {
"pin" : {
"lat" : 10.717,
"lon" : -13.99
}
}
}
]

编写插件可能是解决方案,但是关于编写插件的文档并不多。

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

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

最新更新