基于数字与查询的接近程度进行弹性搜索评分 [英] Elasticsearch scoring based on how close a number is to a query

查看:82
本文介绍了基于数字与查询的接近程度进行弹性搜索评分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据查询的数量接近得分我的文档。鉴于我有两个文件 document1.field = 1 document2.field = 10 ,查询 field = 3 然后我想要 document1._score> document2._score 。或者换句话说,我想要一个像模糊查询的数字。我该如何实现?用例是我想支持价格查询(精确或范围),但是要排序不完全在边界的内容。

I want to score my documents based on on how close a number is to a query. Given I have two documents document1.field = 1 and document2.field = 10, a query field = 3 then I want document1._score > document2._score. Or in other words I want something like a fuzzy query against number. How would I achieve this? The use case is I want to support price queries (exact or range), but want to rank stuff that isn't exactly in the boundaries.

推荐答案

可以使用 custom_score 查询脚本将根据绝对价格和期望价格之间的差异确定升值。应将所需的价格作为参数传递给脚本,以避免对每个请求进行脚本重新编译。

It can be implemented using custom_score query where script will determine boost depending on absolute value of the difference between exact price and desired price. The desired price should be passed to the script as a parameter to avoid script recompilation for every request.

或者,可以使用 custom_filters_score 查询。这里的过滤器将包含所需价格的不同范围。较小的范围将有较高的提升,并在列表中显示较高的范围。

Alternatively, it can be implemented using custom_filters_score query. Filters here will contain different ranges around desired price. Smaller ranges will have higher boost and appear higher in the list than larger ranges.

这篇关于基于数字与查询的接近程度进行弹性搜索评分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆