我在数据中有分数(整数)字段,我从api获取数据,并将其直接发布到localhost:9200 // listings /,并且我希望项目_score等于数据中的分数字段。
目前,一种解决方案是添加?sort=score:desc
到url
一种解决方案是使用function_score
查询,在此您可以_score
使用field_value_factor
评分功能替换默认值。它是这样的:
curl -XPOST localhost:9200/listings/_search -d '{
"query": {
"function_score": {
"functions": [
{
"field_value_factor": {
"field": "score", <---- we use the score field instead
"factor": 1, <---- take the exact same score
"missing": 1 <---- use 1 as score if the score field is missing
}
}
],
"query": {
"match_all": {}
},
"boost_mode": "replace" <---- we're replacing the default _score
}
}
}'
因此,我们基本上是使用score
字段乘以1来计算分数,如果任何文档不包含该score
字段,我们仅假设分数为1(您可以将其更改为更有意义的值)。
更新
根据您的评论,您需要_score
将乘以文档的score
字段。你可以简单地通过移除实现它boost_mode
的参数,默认boost_mode
是multiply
在_score
与任何值包含于该出field_value_factor
功能。
如果您需要完全替换默认的评分机制以基于您的score
字段,那么可以使用一种更复杂的方法使用similarity
模块,在该模块中,您可以只为您的score
字段定义另一个相似性算法。有一篇很棒的博客文章,解释了相似性模块的细节。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句