我在一个带有ElasticSearch 6.8服务器的Rails项目中使用Search腿。我正在努力增加某些文档,这些文档的年份字段与今年或未来的一年相等。
我试过使用boost_where和最近的boost_by,但两者都不起作用。boost_by生成一个function_score函数,该函数在ElasticSearch中出错。这是我最近的尝试。
Model.search('value', boost_by: { year: { scale: '5y' } })
ElasticSearch似乎不喜欢日历间隔(5y),尽管这应该是有效的。下面是错误的原因:
"caused_by": {
"type": "number_format_exception",
"reason": "For input string: \"5y\""
}我尝试过将origin和decay与scale一起设置,但这似乎没有任何帮助。
以下是Searchkick生成的查询(模型和字段名因非常特定的域模型而更改)。
Model Search (163.5ms) model_development/_search {"query":{"function_score":{"functions":[{"weight":1,"gauss":{"year":{"scale":"5y"}}}],"query":{"bool":{"should":[{"dis_max":{"queries":[{"multi_match":{"query":"Abreu","boost":10,"operator":"and","analyzer":"searchkick_search","fields":["*.analyzed"],"type":"best_fields"}},{"multi_match":{"query":"Abreu","boost":10,"operator":"and","analyzer":"searchkick_search2","fields":["*.analyzed"],"type":"best_fields"}},{"multi_match":{"query":"Abreu","boost":1,"operator":"and","analyzer":"searchkick_search","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true,"fields":["*.analyzed"],"type":"best_fields"}},{"multi_match":{"query":"Abreu","boost":1,"operator":"and","analyzer":"searchkick_search2","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true,"fields":["*.analyzed"],"type":"best_fields"}}]}}]}},"score_mode":"sum"}},"timeout":"11s","_source":false,"size":10000}发布于 2020-06-18 22:00:03
年份可能不是受支持的日期格式,因为它没有绝对表示形式。一天是总是 24小时,但是一年有时是364天,通常是365天。与其解决这一复杂问题,我们可能会在几天内停止。
如果你愿意,你可以用天数来衡量你的比例:
Model.search('value', boost_by: { year: { scale: '1825d' } })https://stackoverflow.com/questions/62457450
复制相似问题