elasticsearch - 处理倒数函数时如何防止elasticsearch中的分片失败
问题描述
我必须执行弹性搜索查询,我需要在其中修改查询检索到的文档的分数。我正在使用 function_score 在倒数函数的帮助下修改分数。以下是我的代码,
{
"function_score": {
"query": {
"bool": {
"must": [{"match":{"course": "IT"}}]
}
},
"functions": [{
"field_value_factor": {
"field": "users_score_nested.rank",
"modifier": "reciprocal",
"missing": 1
}
}
],
"boost_mode": "multiply",
"score_mode": "sum"
}
}
在这里,我需要根据课程字段和排名字段的过滤器来更改我的分数。排名值可以有 0、NULL、1、2 等值。对于排名较高的候选人(最低排名值),分数应该很高。但由于 0 或 NULL 值分片失败发生。除了更改排名值之外,有没有办法防止分片失败或者我可以使用除倒数函数之外的任何其他函数吗?
我得到的错误如下,
{
"root_cause": [{
"type": "exception",
"reason": "Result of field modification [reciprocal(0.0)] must be a number"
}],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query"
}
解决方案
您所能做的就是从数据中删除“users_score_nested.rank”,以便 function_score 查询的“missing”参数生效,倒数为 1。
恐怕没有办法绕过异常。或者,您可以使用 function_score 查询的 script_score 参数
"script_score" : {
"script" : {
"source": "Math.pow(doc['users_score_nested']['rank']+1,-1)"
}
}
注意:确保字段的 是"type"
并且它作为映射的一部分包含在父级中。"rank"
"integer"
推荐阅读
- python - 对于 KivyMD MDBottomNavigationItem,是否甚至可以更改文本以使其不是全部大写?
- ios - 如何在到期前正确更新 Xcode 托管配置文件?
- python - 让机器人在 Python 中同时执行一组动作(使用 selenium)
- java - 如何使用多个排序匹配进行排序?
- python - 在某个值之后划分列表或数据框
- amazon-web-services - 重命名用户和跨账户策略行为
- javascript - UnhandledPromiseRejectionWarning:错误:协议错误(Page.navigate):当我传递有效 URL 时无法导航到无效 URL
- azure-table-storage - 我在哪里可以找到存储表功能的实际实现?
- wordpress - 在域的子目录下托管两个不同的应用程序
- css - 减小屏幕尺寸时我的列重叠