0
我正在使用ES 2.4.1并需要使用内联脚本来按表达式计算字段,例如,如何处理elasticsearch脚本分区零错误?
POST http://192.168.100.223:9200/bttest/_update_by_query
{
"script": {
"inline": "ctx._source.'503'= ctx._source.'101'/(
ctx._source.'104'* ctx._source.'105')",
"lang": "groovy"
},
"query": {
"bool": {
"must": [
{"exists": {"field": "101"}} , {"exists": {"field": "104"}} , {"exists": {"field": "105"}} ]
}
}
}
当在外地“105” 0,此执行将异常失败
{"error":{"root_cause":[{"type":"script_exception","reason":"failed to run inline script [ctx._source.'503'= ctx._source.'101'/(ctx._source.'104'* ctx._source.'105')] using lang [groovy]"}],"type":"script_exception","reason":"failed to run inline script [ctx._source.'503'= ctx._source.'101'/(ctx._source.'104'* ctx._source.'105')] using lang [groovy]","caused_by":{"type":"arithmetic_exception","reason":"Division by zero"}},"status":500}
我该如何处理这种划分的零错误,我希望它可以捕获该异常,并继续计算或者在满足零点时将新场设置为无限。
由于表达式是由用户输入的,因此检查所有除数是否为零并非易事。
谢谢
你的意思是说用户自己写脚本表达式?这真的不是一个好主意,除非你不关心集群的完整性。 – Val
@Val感谢您的评论。实际上,要求是管理员角色的用户可以动态地添加新的字段,并且可以从现有字段计算新字段。 –