Update by query problem

Hi everyone

I'm trying to create a new field in my index, and the value for it must be a substring from another field. This is my code:

POST logstash-2018.06.26/_update_by_query
{
    "script" : {
        "source": "ctx._source.seq = ctx._source.mensaje.substring(0, 2)",
        "lang": "painless"
    }
}

The new field would be 'seq'. The problem is that i'm getting null pointer exception in the substring function. There is no null value in that field, and it happens with other _source fields too. In fact, if i remove the substring function, it works just fine.

I cannot use doc fields because the field i need is analyzed/keyword, so i cannot apply the substring function on it.

Here is the error:

{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "runtime error",
        "script_stack": [
          "ctx._source.seq = ctx._source.mensaje.substring(0, 2)",
          "                                     ^---- HERE"
        ],
        "script": "ctx._source.seq = ctx._source.mensaje.substring(0, 2)",
        "lang": "painless"
      }
    ],
    "type": "script_exception",
    "reason": "runtime error",
    "script_stack": [
      "ctx._source.seq = ctx._source.mensaje.substring(0, 2)",
      "                                     ^---- HERE"
    ],
    "script": "ctx._source.seq = ctx._source.mensaje.substring(0, 2)",
    "lang": "painless",
    "caused_by": {
      "type": "null_pointer_exception",
      "reason": null
    }
  },
  "status": 500
}

Isn't the substring function supposed to be
applicable to the ctx._source fields the same way it is applicable to params._source.field in a scripted field?

Thanks in advance

I apologize, given the fact that i've been testing a lot of stuff, i activated the field_data in the 'mensaje' field. The problem was that the substring function couldn't operate on a field with that activated.

Sorry again, this topic is resolved.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.