# \[ingest-pipeline\] remove field from target index

**URL:** <https://discuss.elastic.co/t/ingest-pipeline-remove-field-from-target-index/354113>\
**Category:** Elasticsearch\
**Tags:** ingest-pipeline\
**Created:** [February 26, 2024, 10:39am UTC](https://discuss.elastic.co/t/ingest-pipeline-remove-field-from-target-index/354113 "2024-02-26T10:39:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![seddikalaouiismaili](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seddikalaouiismaili/32/87834_2.png) [@seddikalaouiismaili](https://discuss.elastic.co/u/seddikalaouiismaili)\
**Post date:** [February 26, 2024, 10:39am UTC](https://discuss.elastic.co/t/ingest-pipeline-remove-field-from-target-index/354113/1 "2024-02-26T10:39:49Z")

</div>

Hi community,

I'm trying delete some unused fields from index, through the ingest pipeline.

**Current config :**

```auto
        "remove": {
            "if": "ctx._index.contains('stg-index-short-')",
            "field": "message"
        }
    }

```

**Expected behavior :**

```auto
_index: stg-index-short-*   

```

should return nothing

**Current behavior :**

Still having message field on the index stg-index-short-\*

There is any another way to delete this field from target ?

Thank you for your help

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [February 26, 2024, 12:04pm UTC](https://discuss.elastic.co/t/ingest-pipeline-remove-field-from-target-index/354113/2 "2024-02-26T12:04:04Z")

</div>

I don't think you can use the `_index` field to filter since it may only exists after all the processing is done.

You will need to use another filter to field.

---

<div class="post-metadata">

**Author:** ![seddikalaouiismaili](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seddikalaouiismaili/32/87834_2.png) [@seddikalaouiismaili](https://discuss.elastic.co/u/seddikalaouiismaili)\
**Post date:** [February 26, 2024, 2:18pm UTC](https://discuss.elastic.co/t/ingest-pipeline-remove-field-from-target-index/354113/3 "2024-02-26T14:18:37Z")

</div>

thank you for the reply ..  
I tried to filter with another field, but didn't help

```auto
    {
        "remove": {
            "if": "lg.meta.component == indexshort",
            "field": "message"
        }
    }

```

I got this error

```auto
Could not Put pipeline stg-pipeline : [{'type': 'script_exception', 'reason': 'compile error', 'processor_type': 'remove', 'script_stack':

```

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [February 26, 2024, 2:52pm UTC](https://discuss.elastic.co/t/ingest-pipeline-remove-field-from-target-index/354113/4 "2024-02-26T14:52:14Z")

</div>

Please share the entire error.

Also, If I'm not wrong the conditional is wrong.

It needs to be something like this: `ctx.lg?.meta?.componet == 'indexshort'"`

---

<div class="post-metadata">

**Author:** ![seddikalaouiismaili](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seddikalaouiismaili/32/87834_2.png) [@seddikalaouiismaili](https://discuss.elastic.co/u/seddikalaouiismaili)\
**Post date:** [February 28, 2024, 12:20pm UTC](https://discuss.elastic.co/t/ingest-pipeline-remove-field-from-target-index/354113/5 "2024-02-28T12:20:02Z")

</div>

Thank you that works fine 😉

---

<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:** [March 27, 2024, 12:20pm UTC](https://discuss.elastic.co/t/ingest-pipeline-remove-field-from-target-index/354113/6 "2024-03-27T12:20:13Z")

</div>

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