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.

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.