如何从Elasticsearch Painless _reindex脚本错误消息中找到违规记录?

cbjzeqam  于 2023-05-22  发布在  ElasticSearch
关注(0)|答案(2)|浏览(156)

我在一个较大的索引上运行_reindex,得到以下错误:

{
  "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
}

这个错误是合法的,我很乐意改进我的脚本,但我想有更多的上下文。有没有一种方法可以从错误消息中看到有问题的值或它的记录id?有没有一个try/catch方法可以在脚本中使用?

t9eec4r0

t9eec4r01#

是的,您可以尝试/捕获语句,然后像这样从源代码中Debug任何值

try {
    ctx._source.es_resync_time = ctx._source.es_resync_time / 1000000;
} catch (Exception e) {
    Debug.explain(ctx._source)
}
nle07wnf

nle07wnf2#

代码中有一个“class_cast_exception”,当尝试将除法(/)操作应用于字符串和整数时会发生。要修复此问题,您需要在执行除法运算之前确保“es_resync_time”字段为数值类型。

{
  "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
}

相关问题