# Ctx.\_field\_names is null

**URL:** https://discuss.elastic.co/t/ctx--field-names-is-null/96476
**Category:** Elasticsearch
**Created:** [August 9, 2017, 4:44pm UTC](https://discuss.elastic.co/t/ctx--field-names-is-null/96476 "2017-08-09T16:44:07Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![simonlucalandi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonlucalandi/32/14990_2.png) [@simonlucalandi](https://discuss.elastic.co/u/simonlucalandi)
#### Post date: [August 9, 2017, 4:44pm UTC](https://discuss.elastic.co/t/ctx--field-names-is-null/96476/1 "2017-08-09T16:44:08Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [September 6, 2017, 4:44pm UTC](https://discuss.elastic.co/t/ctx--field-names-is-null/96476/2 "2017-09-06T16:44:50Z")

</div>

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