# Add field with the length of value of other field

**URL:** <https://discuss.elastic.co/t/add-field-with-the-length-of-value-of-other-field/149249>\
**Category:** Logstash\
**Created:** [September 20, 2018, 8:27am UTC](https://discuss.elastic.co/t/add-field-with-the-length-of-value-of-other-field/149249 "2018-09-20T08:27:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alfonso.viso](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@alfonso.viso](https://discuss.elastic.co/u/alfonso.viso)\
**Post date:** [September 20, 2018, 8:27am UTC](https://discuss.elastic.co/t/add-field-with-the-length-of-value-of-other-field/149249/1 "2018-09-20T08:27:56Z")

</div>

Hi all,

I'm trying to create a new field which value must be the length of the string of another field.  
I have found an advice using ruby code, like this:

//ruby {  
// code =\> "event.set['http\_user\_agent\_length'] = event.get['http\_user\_agent'].length"  
// }  
// }  
the type of "http\_user\_agent" is string.

When I execute this code, I receive this message:

[ERROR] 2018-09-20 08:19:13.047 [Ruby-0-Thread-7: :1] ruby - Ruby exception occurred: wrong number of arguments calling `set` (0 for 2)

Anyone know the issue or other way to obtain the length of a field?

Thank you,

Best Regards

---

<div class="post-metadata">

**Author:** ![alfonso.viso](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@alfonso.viso](https://discuss.elastic.co/u/alfonso.viso)\
**Post date:** [September 20, 2018, 8:48am UTC](https://discuss.elastic.co/t/add-field-with-the-length-of-value-of-other-field/149249/2 "2018-09-20T08:48:52Z")

</div>

Hi again,  
I get the solution. I have used this code and work it:  
//  
ruby {  
code =\> 'event.set("http\_user\_agent\_lenght",event.get("http\_user\_agent").length)'  
}  
//

Thanks,

Regards

---

<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:** [October 18, 2018, 8:48am UTC](https://discuss.elastic.co/t/add-field-with-the-length-of-value-of-other-field/149249/3 "2018-10-18T08:48:58Z")

</div>

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