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感謝您的評論。實際上,要求是管理員角色的用戶可以動態地添加新的字段,並且可以從現有字段計算新字段。 –