Ctx._field_names is null

Hello.
I'm running ES 5.5
I need to delete many fields from an index; all of them have the name starting with "amp", so I'm trying to use the _reindex API with an inline script like this:

POST _reindex
{
  "source": {
    "index": "logstash-2017.07.14"
  },
  "dest": {
    "index": "logstash-2017.07.14-fixed"
  },
  "script": {
    "inline": """
    HashMap names = ctx._field_names;
	  for (field in names.entrySet()) {
	    if(field =~ /^amp/) {
           ctx._source.remove(field);
		}
	  }
"""
  }
}

but from what I undestand, the ctx._field_names returns null

{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "runtime error",
        "script_stack": [
          "for (field in names.entrySet()) {\n\t    ",
          "                   ^---- HERE"
        ],
        "script": "    HashMap names = ctx._field_names;\n\t  for (field in names.entrySet()) {\n\t    if(field =~ /^amp/) {\n           ctx._source.remove(field);\n\t\t}\n\t  }",
        "lang": "painless"
      }
    ],
    "type": "script_exception",
    "reason": "runtime error",
    "script_stack": [
      "for (field in names.entrySet()) {\n\t    ",
      "                   ^---- HERE"
    ],
    "script": "    HashMap names = ctx._field_names;\n\t  for (field in names.entrySet()) {\n\t    if(field =~ /^amp/) {\n           ctx._source.remove(field);\n\t\t}\n\t  }",
    "lang": "painless",
    "caused_by": {
      "type": "null_pointer_exception",
      "reason": null
    }
  },
  "status": 500
}

Any suggestion or workaround for this?

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