# Implement custom code in Filter plugin for Logstash

**URL:** https://discuss.elastic.co/t/implement-custom-code-in-filter-plugin-for-logstash/360615
**Category:** Logstash
**Created:** [May 31, 2024, 10:20am UTC](https://discuss.elastic.co/t/implement-custom-code-in-filter-plugin-for-logstash/360615 "2024-05-31T10:20:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Manoilayans](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@Manoilayans](https://discuss.elastic.co/u/Manoilayans)
#### Post date: [May 31, 2024, 10:20am UTC](https://discuss.elastic.co/t/implement-custom-code-in-filter-plugin-for-logstash/360615/1 "2024-05-31T10:20:29Z")

</div>

While ingesting the data we can using Filters like

filter {  
mutate {  
copy =\> { "source\_field" =\> "dest\_field" }  
}  
}

But we need to implement as listed below..

· Proper case  
· Proper punctuation  
· Avoid duplicate titles  
· Line breaks should be html tag \< br \>, \< p \>  
· Bullets should be bullets (not “\_”, “-”, “;”,“~”)

Is it possible using out of the box filters or can we use our custom python code or any other language script to transform the data before storing into Elasticsearch ?

---

<div class="post-metadata">

### Author: ![Rios](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rios/32/95745_2.png) [@Rios](https://discuss.elastic.co/u/Rios)
#### Post date: [May 31, 2024, 11:26am UTC](https://discuss.elastic.co/t/implement-custom-code-in-filter-plugin-for-logstash/360615/2 "2024-05-31T11:26:00Z")

</div>

You can use:

- [mutate](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html), uppercase, capitalize,lowercase,gsub, etc.
- Avoid duplicate titles - not clear what does it means, ruby code could help
- Line breaks, bullets,... gsub should help.  
Check other the filter plugins or use ruby code

---

<div class="post-metadata">

### Author: ![Manoilayans](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@Manoilayans](https://discuss.elastic.co/u/Manoilayans)
#### Post date: [June 2, 2024, 6:07am UTC](https://discuss.elastic.co/t/implement-custom-code-in-filter-plugin-for-logstash/360615/3 "2024-06-02T06:07:04Z")

</div>

Thanks.. Pls share some ruby code for example make the string into uppercase

---

<div class="post-metadata">

### Author: ![Rios](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rios/32/95745_2.png) [@Rios](https://discuss.elastic.co/u/Rios)
#### Post date: [June 2, 2024, 2:21pm UTC](https://discuss.elastic.co/t/implement-custom-code-in-filter-plugin-for-logstash/360615/4 "2024-06-02T14:21:19Z")

</div>

You can use mutate or ruby code, it's up to you

```auto
input {
  generator {
       message => "Test message"
	   count => 1
  }
}
filter {

   mutate {
     copy => { "message" => "msgmutate" }
   }
   mutate { 
     lowercase => ["msgmutate"]
   }

    ruby {
     code => "event.set('message', event.get('message').upcase )"
	}

    mutate { remove_field => ["host", "log"] }

}

output {
    stdout { }
}

```

Output:

```auto
{
         "event" => {
        "original" => "Test message",
        "sequence" => 0
    },
       "message" => "TEST MESSAGE",
     "msgmutate" => "test message"
}

```
