# Truncation of field values in grok filter

**URL:** https://discuss.elastic.co/t/truncation-of-field-values-in-grok-filter/105531
**Category:** Logstash
**Created:** [October 27, 2017, 7:36am UTC](https://discuss.elastic.co/t/truncation-of-field-values-in-grok-filter/105531 "2017-10-27T07:36:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Rupesh\_Ranjan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rupesh_ranjan/32/22283_2.png) [@Rupesh\_Ranjan](https://discuss.elastic.co/u/Rupesh_Ranjan)
#### Post date: [October 27, 2017, 7:36am UTC](https://discuss.elastic.co/t/truncation-of-field-values-in-grok-filter/105531/1 "2017-10-27T07:36:01Z")

</div>

How can i truncate a field value in grok?

e.g. I have a field **"value: abcdefgh1234567890"** in logstash(obtained from message after grok filter)

> match =\> { "message" =\> "%{GREEDYDATA}value=%{WORD:value}"}

and i want to truncate value to show only 5 chracters and append xxxxx for rest, so the value i want to send to _elasticsearch_ will be **"value: abcdexxxxxxxxxxxxx".**

---

<div class="post-metadata">

### Author: ![paz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paz/32/28003_2.png) [@paz](https://discuss.elastic.co/u/paz)
#### Post date: [October 30, 2017, 3:12pm UTC](https://discuss.elastic.co/t/truncation-of-field-values-in-grok-filter/105531/2 "2017-10-30T15:12:54Z")

</div>

I don't think you can do that in grok, you probably need some custom ruby code after your grok filter, like:

```auto
filter {
    ruby {
        code => "
            event.set('value', event.get('value')[0..4] + ('x' * (event.get('value').length - 6)))
        "
    }
}
```

---

<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: [November 27, 2017, 3:13pm UTC](https://discuss.elastic.co/t/truncation-of-field-values-in-grok-filter/105531/3 "2017-11-27T15:13:41Z")

</div>

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