英文:
How to find the offending record from Elasticsearch Painless _reindex script error message?
问题
I'm running a _reindex
on a large-ish index, and getting this error:
{
"error" : {
"root_cause" : [
{
"type" : "script_exception",
"reason" : "runtime error",
"script_stack" : [
"ctx._source.es_resync_time = ctx._source.es_resync_time / 1000000;\n }\n }\n ",
" ^---- HERE"
],
"script" : " ...",
"lang" : "painless",
"position" : {
"offset" : 1911,
"start" : 1871,
"end" : 1962
}
}
],
"type" : "script_exception",
"reason" : "runtime error",
"script_stack" : [
"ctx._source.es_resync_time = ctx._source.es_resync_time / 1000000;\n }\n }",
" ^---- HERE"
],
"script" : " ...",
"lang" : "painless",
"position" : {
"offset" : 1911,
"start" : 1871,
"end" : 1962
},
"caused_by" : {
"type" : "class_cast_exception",
"reason" : "Cannot apply [/] operation to types [java.lang.String] and [java.lang.Integer]."
}
},
"status" : 400
}
The error is legit and I'd be happy to improve my script, but I'd like to have a bit more context. Is there a way to see the offending value or its record id from the error message? Is there a try/catch method I can use in the script for this?
英文:
I'm running a _reindex
on a large-ish index, and getting this error:
{
"error" : {
"root_cause" : [
{
"type" : "script_exception",
"reason" : "runtime error",
"script_stack" : [
"ctx._source.es_resync_time = ctx._source.es_resync_time / 1000000;\n }\n }\n ",
" ^---- HERE"
],
"script" : " ...",
"lang" : "painless",
"position" : {
"offset" : 1911,
"start" : 1871,
"end" : 1962
}
}
],
"type" : "script_exception",
"reason" : "runtime error",
"script_stack" : [
"ctx._source.es_resync_time = ctx._source.es_resync_time / 1000000;\n }\n }\n ",
" ^---- HERE"
],
"script" : " ...",
"lang" : "painless",
"position" : {
"offset" : 1911,
"start" : 1871,
"end" : 1962
},
"caused_by" : {
"type" : "class_cast_exception",
"reason" : "Cannot apply [/] operation to types [java.lang.String] and [java.lang.Integer]."
}
},
"status" : 400
}
The error is legit and I'd be happy to improve my script, but I'd like to have a bit more context. Is there a way to see the offending value or its record id from the error message? Is there a try/catch method I can use in the script for this?
答案1
得分: 1
在代码中出现了一个“class_cast_exception”,当尝试将除法(/)操作应用于字符串和整数时会发生这种情况。要修复它,您需要确保在执行除法操作之前,“es_resync_time”字段是数值类型。
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "运行时错误",
"script_stack": [
"try {",
" if (ctx._source.es_resync_time instanceof String) {",
" ctx._source.es_resync_time = Double.parseDouble(ctx._source.es_resync_time);",
" }",
" ctx._source.es_resync_time = ctx._source.es_resync_time / 1000000;",
"} catch (e) {",
" ctx._source.error_message = e.toString();",
"}"
],
"script": "...",
"lang": "painless",
"position": {
"offset": 1911,
"start": 1871,
"end": 1962
}
}
],
"type": "script_exception",
"reason": "运行时错误",
"script_stack": [
"try {",
" if (ctx._source.es_resync_time instanceof String) {",
" ctx._source.es_resync_time = Double.parseDouble(ctx._source.es_resync_time);",
" }",
" ctx._source.es_resync_time = ctx._source.es_resync_time / 1000000;",
"} catch (e) {",
" ctx._source.error_message = e.toString();",
"}"
],
"script": "...",
"lang": "painless",
"position": {
"offset": 1911,
"start": 1871,
"end": 1962
},
"caused_by": {
"type": "class_cast_exception",
"reason": "无法将 [/] 操作应用于类型 [java.lang.String] 和 [java.lang.Integer]。"
}
},
"status": 400
}
英文:
In the code is a "class_cast_exception" that occurs when trying to apply the division (/) operation to a string and an integer. To fix it, you need to ensure that the "es_resync_time" field is of numeric type before performing the division operation.
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"try {",
" if (ctx._source.es_resync_time instanceof String) {",
" ctx._source.es_resync_time = Double.parseDouble(ctx._source.es_resync_time);",
" }",
" ctx._source.es_resync_time = ctx._source.es_resync_time / 1000000;",
"} catch (e) {",
" ctx._source.error_message = e.toString();",
"}"
],
"script": "...",
"lang": "painless",
"position": {
"offset": 1911,
"start": 1871,
"end": 1962
}
}
],
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"try {",
" if (ctx._source.es_resync_time instanceof String) {",
" ctx._source.es_resync_time = Double.parseDouble(ctx._source.es_resync_time);",
" }",
" ctx._source.es_resync_time = ctx._source.es_resync_time / 1000000;",
"} catch (e) {",
" ctx._source.error_message = e.toString();",
"}"
],
"script": "...",
"lang": "painless",
"position": {
"offset": 1911,
"start": 1871,
"end": 1962
},
"caused_by": {
"type": "class_cast_exception",
"reason": "Cannot apply [/] operation to types [java.lang.String] and [java.lang.Integer]."
}
},
"status": 400
}
答案2
得分: 1
是的,你可以尝试使用try/catch语句,然后像这样调试源中的任何值
try {
ctx._source.es_resync_time = ctx._source.es_resync_time / 1000000;
} catch (Exception e) {
Debug.explain(ctx._source)
}
英文:
Yes, you can try/catch the statement and then Debug any value from the source like this
try {
ctx._source.es_resync_time = ctx._source.es_resync_time / 1000000;
} catch (Exception e) {
Debug.explain(ctx._source)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论