Searchkick:提升未来日期

Searchkick: Boosting future dates

我在带有 ElasticSearch 6.8 服务器的 Rails 项目中使用 Searchkick。我正在尝试提升某些年份字段等于今年或未来一年的文档。

我试过使用 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\""
          }

我已经尝试设置 origindecay 以及 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}

年份可能不是受支持的日期格式,因为它没有绝对表示法。一天是总是 24 小时,但一年是有时 364 天和通常 365 天。 ES 可能会在几天内停止,而不是解决这种复杂性。

如果需要,您可以使用天数作为体重秤:

Model.search('value', boost_by: { year: { scale: '1825d' } })