elasticsearchelasticsearch-painless

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      }\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?


Solution

  • 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)
    }