# Logstash Ruby Filter Not Removing Fields

**URL:** https://discuss.elastic.co/t/logstash-ruby-filter-not-removing-fields/225297
**Category:** Logstash
**Created:** [March 26, 2020, 9:31pm UTC](https://discuss.elastic.co/t/logstash-ruby-filter-not-removing-fields/225297 "2020-03-26T21:31:20Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Rahul\_Kumar4](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahul_kumar4/32/67369_2.png) [@Rahul\_Kumar4](https://discuss.elastic.co/u/Rahul_Kumar4)
#### Post date: [March 26, 2020, 9:31pm UTC](https://discuss.elastic.co/t/logstash-ruby-filter-not-removing-fields/225297/1 "2020-03-26T21:31:20Z")

</div>

Hello,

I have logs that look like this

```
{
    "attachments" : [ 
        {
            "field1" : "rkredux",
            "inner_value" : [
                "check"
            ]
        },
        {
            "field1" : "kkrist",
            "inner_value" : [
                "uncheck"
            ]
        },
        {
            "field1" : "uuiui2",
            "inner_value" : [
                "mblake"
            ]
        }
    ]
}

```

and my LS pipeline with a ruby filter looks like this

```
input {
  http {
    port => 5011
  }
  
}
filter {
  json{
    source => "message"
  }

  ruby {
    code => 
    "
      index = -1
      for inner in event.get('[attachments]') do
        index += 1
          event.remove('[attachments][index][inner_value]')
      end
    "
  }

}

output {
  stdout {
  }
}

```

But this pipeline does not remove the inner\_value array from the fields inside and does not throw any ruby exception either. I expect my output logs to look like this

```
{
        "attachments" : [ 
            {
                "field1" : "rkredux"
            },
            {
                "field1" : "kkrist"
               
            },
            {
                "field1" : "uuiui2"
            
            }
        ]
    }
```

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [March 26, 2020, 11:11pm UTC](https://discuss.elastic.co/t/logstash-ruby-filter-not-removing-fields/225297/2 "2020-03-26T23:11:34Z")

</div>

Try something like [this](https://discuss.elastic.co/t/remove-subfield-using-ruby/225055/4).

---

<div class="post-metadata">

### Author: ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)
#### Post date: [March 27, 2020, 8:54am UTC](https://discuss.elastic.co/t/logstash-ruby-filter-not-removing-fields/225297/3 "2020-03-27T08:54:32Z")

</div>

Hi Rahul,

what about something like:

```
ruby {
  code => "
    attachments = event.get('attachments').map { |item| item.delete('inner_value') }
    event.set('attachments', attachments)
  "
}
```

---

<div class="post-metadata">

### Author: ![Rahul\_Kumar4](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahul_kumar4/32/67369_2.png) [@Rahul\_Kumar4](https://discuss.elastic.co/u/Rahul_Kumar4)
#### Post date: [March 28, 2020, 11:06am UTC](https://discuss.elastic.co/t/logstash-ruby-filter-not-removing-fields/225297/4 "2020-03-28T11:06:33Z")

</div>

Thanks. @Fabio-sama That returns this but that is not what I am looking for. See snippet below from a docker stdout.

```
attachments" => [
logstash | [0] [
logstash | [0] "check"
logstash | ],
logstash | [1] [
logstash | [0] "uncheck"
logstash | ],
logstash | [2] [
logstash | [0] "mblake"
logstash | ]
logstash | ],
```

---

<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: [April 25, 2020, 11:06am UTC](https://discuss.elastic.co/t/logstash-ruby-filter-not-removing-fields/225297/5 "2020-04-25T11:06:37Z")

</div>

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