# Remove a Field using a wildcard on reindex

**URL:** <https://discuss.elastic.co/t/remove-a-field-using-a-wildcard-on-reindex/182448>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [May 23, 2019, 1:28pm UTC](https://discuss.elastic.co/t/remove-a-field-using-a-wildcard-on-reindex/182448 "2019-05-23T13:28:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hogbinj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hogbinj/32/14744_2.png) [@hogbinj](https://discuss.elastic.co/u/hogbinj)\
**Post date:** [May 23, 2019, 1:28pm UTC](https://discuss.elastic.co/t/remove-a-field-using-a-wildcard-on-reindex/182448/1 "2019-05-23T13:28:50Z")

</div>

I've done a foolish thing and created a large number of fields in the format

```auto
 "fingerprint.attachment_5C6C2D4E000092B707F41EF1" : "Attachment 5C6C2D4E000092B707F41EF1.gif is an IMAGE and therfore NOT processed"

```

I used an underscore rather than a period

I'm trying to reindex to remove these fields using this pipeline but it's not working. Can anybody point out where I'm going wrong.

```auto
PUT _ingest/pipeline/remove-fingerprint-attachment-field
{
  "description" : "Remove Fingerprint Attachment Field pipeline",
  "processors" : [
     {
     "foreach" : {
        "field" : "fingerprint",
         "processor" : {
            "script": {
              "lang": "painless",
              "source": "if (ctx._ingest._value.contains(params.field_part)) {ctx._ingest_value.remove}",
              "params": {
                "params":
                  {"field_part":"attachment_"}
              }
            }
          }
        }
    }  
  ]
}

```

The error is

```auto
"cause": {
  "type": "exception",
  "reason": "java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: field [fingerprint] not present as part of path [fingerprint]",
  "caused_by": {
    "type": "illegal_argument_exception",
    "reason": "java.lang.IllegalArgumentException: field [fingerprint] not present as part of path [fingerprint]",
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "field [fingerprint] not present as part of path [fingerprint]"
    }
  },
  "header": {
    "processor_type": "foreach"
  }
}
```

---

<div class="post-metadata">

**Author:** ![jpcarey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpcarey/32/46668_2.png) [@jpcarey](https://discuss.elastic.co/u/jpcarey)\
**Post date:** [May 23, 2019, 11:19pm UTC](https://discuss.elastic.co/t/remove-a-field-using-a-wildcard-on-reindex/182448/2 "2019-05-23T23:19:16Z")

</div>

> [@hogbinj](#):
>
> "fingerprint.attachment\_5C6C2D4E000092B707F41EF1"

`foreach` would iterate on an array, which the source data does not appear to match that.

You could likely do this with just a reindex script rather than needing to use an ingest pipeline. Below is a quick sample using the ingest simulate with an ingest script processor to add the values to a list (if there are multiple) and remove.

```json
POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "description": "_description",
    "processors": [
      {
        "script": {
          "lang": "painless",
          "source": """
Iterator it = ctx.entrySet().iterator();
def tmp_list = new ArrayList();
while (it.hasNext()) {
  def k = it.next();
  if (k.getKey().contains("fingerprint.attachment_")) {
    tmp_list.add(k.getValue());
    it.remove();
  }
}
ctx.put("fingerprint.errors", tmp_list);
"""
        }
      }
    ]
  },
  "docs": [
    {
      "_index": "index",
      "_id": "id",
      "_source": {
        "fingerprint.attachment_5C6C2D4E000092B707F41EF1": "Attachment 5C6C2D4E000092B707F41EF1.gif is an IMAGE and therfore NOT processed",
        "fingerprint.attachment_5C6C2D4E000092B707F41EF2": "Attachment 5C6C2D4E000092B707F41EF2.gif is an IMAGE and therfore NOT processed",
        "test_key": 1,
        "test_object": {
          "test_key2": "key 2"
        },
        "test_array": [
          "value1",
          "value2"
        ]
      }
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![hogbinj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hogbinj/32/14744_2.png) [@hogbinj](https://discuss.elastic.co/u/hogbinj)\
**Post date:** [May 24, 2019, 8:03am UTC](https://discuss.elastic.co/t/remove-a-field-using-a-wildcard-on-reindex/182448/3 "2019-05-24T08:03:17Z")

</div>

THANK YOU VERY MUCH!!

how do I find out where to script painless like that. I spent ages on the ES website but missed the Iterator part.

Is there an idiots guide anywhere?

James

---

<div class="post-metadata">

**Author:** ![jpcarey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpcarey/32/46668_2.png) [@jpcarey](https://discuss.elastic.co/u/jpcarey)\
**Post date:** [May 26, 2019, 6:37pm UTC](https://discuss.elastic.co/t/remove-a-field-using-a-wildcard-on-reindex/182448/4 "2019-05-26T18:37:53Z")

</div>

Personally, just look for java examples on the web, and pay close attention to the slight differences in syntax and the [whitelisted java classes](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-api-reference.html) for painless.

---

<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:** [June 23, 2019, 6:37pm UTC](https://discuss.elastic.co/t/remove-a-field-using-a-wildcard-on-reindex/182448/5 "2019-06-23T18:37:58Z")

</div>

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