# Implement the prune filter using painless script in ingest pipeline

**URL:** <https://discuss.elastic.co/t/implement-the-prune-filter-using-painless-script-in-ingest-pipeline/218619>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [February 10, 2020, 3:18pm UTC](https://discuss.elastic.co/t/implement-the-prune-filter-using-painless-script-in-ingest-pipeline/218619 "2020-02-10T15:18:30Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Sarfaraz\_Ahmad](https://avatars.discourse-cdn.com/v4/letter/s/67e7ee/32.png) [@Sarfaraz\_Ahmad](https://discuss.elastic.co/u/Sarfaraz_Ahmad)\
**Post date:** [February 10, 2020, 5:07pm UTC](https://discuss.elastic.co/t/implement-the-prune-filter-using-painless-script-in-ingest-pipeline/218619/2 "2020-02-10T17:07:16Z")

</div>

I got it. This works. But it seems dirty and performance intensive 😑

```
   {
 "script": {
   "lang": "painless",
   "source": """
    ctx.to_keep = new ArrayList();
    ctx.to_drop = new ArrayList();
    ctx.to_keep = ['field1', 'field2'];
    for (key in ctx.keySet()) {
      if (! ctx.to_keep.contains(key)) {
        ctx.to_drop.add(key);
      }
    }
    for (key in ctx.to_drop) {
        ctx.remove(key);
    }
   """
 }

```

I am not sure how efficient this is. Can someone from elastic please take a look here ?

---

_[View the full topic](https://discuss.elastic.co/t/implement-the-prune-filter-using-painless-script-in-ingest-pipeline/218619)._
