# Adding field for string length

**URL:** <https://discuss.elastic.co/t/adding-field-for-string-length/58958>\
**Category:** Logstash\
**Created:** [August 25, 2016, 4:41pm UTC](https://discuss.elastic.co/t/adding-field-for-string-length/58958 "2016-08-25T16:41:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![megamax](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@megamax](https://discuss.elastic.co/u/megamax)\
**Post date:** [August 25, 2016, 4:41pm UTC](https://discuss.elastic.co/t/adding-field-for-string-length/58958/1 "2016-08-25T16:41:40Z")

</div>

Hello,

Newbie here. I'm trying to add a field to hold the string length of another field in my input. I want to visualize the string lengths (to show average email message sizes by user for example).

I have tried the following but it puts "%{contents.length}" into the contentLength field.

mutate {  
add\_field =\> {"contentLength" =\> "%{contents.length}"}  
}

Is there a way to do this? I could not find a way to do it in Kibana, so I figured I'd move down the stack. Any help would be greatly appreciated.

Thanks

Mark

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [August 25, 2016, 4:53pm UTC](https://discuss.elastic.co/t/adding-field-for-string-length/58958/2 "2016-08-25T16:53:49Z")

</div>

Use a ruby filter:

```nohighlight
ruby {
  code => "event['contentLength'] = event['contents'].length"
}

```

---

<div class="post-metadata">

**Author:** ![megamax](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@megamax](https://discuss.elastic.co/u/megamax)\
**Post date:** [August 25, 2016, 6:26pm UTC](https://discuss.elastic.co/t/adding-field-for-string-length/58958/3 "2016-08-25T18:26:38Z")

</div>

Perfect. Thank you very much.

---

<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:** [July 6, 2017, 4:41am UTC](https://discuss.elastic.co/t/adding-field-for-string-length/58958/4 "2017-07-06T04:41:34Z")

</div>


