0

So I am trying to reindex one of my indices to a temporary one and remove an array list: platform.platforms.*

This is what my Kibana query looks like:

POST /_reindex
{
  "source": {
    "index": "devops-ucd-000001"
  },
  "dest": {
    "index": "temp-ucd"
  },

  "conflicts": "proceed",

  "script": {
    "lang": "painless",
    "inline": "ctx._source.platform.platforms.removeAll(Collections.singleton('1'))"
  }
}

However what I get is a null pointer exception:

"script_stack": [
  "ctx._source.platform.platforms.removeAll(Collections.singleton('1'))",
  "                    ^---- HERE"
],
"script": "ctx._source.platform.platforms.removeAll(Collections.singleton('1'))",
"lang": "painless",
"caused_by": {
  "type": "null_pointer_exception",
  "reason": null
}

I tried following this question: how to remove arraylist value in elastic search using curl? to no avail.

Any help would be appreciated here.

Tom Smith
  • 57
  • 5

1 Answers1

1

It is probably due to some documents not having platform field. You need to add additional checks in your script to ignore such documents

"script": {
    "lang": "painless",
    "inline": """
                  if(ctx._source.platform!=null && ctx._source.platform.platforms!=null && ctx._source.platform.platforms instanceof List)
                  {
                    ctx._source.platform.platforms.removeAll(Collections.singleton('1'))
                  }
              """
  }

Above has null check on platform and platform.platforms also if platforms is of type list

jaspreet chahal
  • 8,817
  • 2
  • 11
  • 29