# How to get the value of fields that not string type

**URL:** https://discuss.elastic.co/t/how-to-get-the-value-of-fields-that-not-string-type/131737
**Category:** Logstash
**Created:** [May 14, 2018, 12:21pm UTC](https://discuss.elastic.co/t/how-to-get-the-value-of-fields-that-not-string-type/131737 "2018-05-14T12:21:55Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![floyd\_fan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/floyd_fan/32/47627_2.png) [@floyd\_fan](https://discuss.elastic.co/u/floyd_fan)
#### Post date: [May 14, 2018, 12:21pm UTC](https://discuss.elastic.co/t/how-to-get-the-value-of-fields-that-not-string-type/131737/1 "2018-05-14T12:21:55Z")

</div>

I want to add a non-string type field A( long type or json type) to logstash output, and set it's value by another field B .  
so i need to access the value of B.  
almost all examples related to accessing field value are nested in a string as:  
" the longitude is %{[geoip][location][0]}"

i want to get field value in it's original type, like json,

add\_field =\> ["location2", [geoip][location] ]  
or  
add\_field =\> ["location2", %{[geoip][location]} ]

but pase error.  
so what is the correct method?

---

<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: [May 14, 2018, 12:54pm UTC](https://discuss.elastic.co/t/how-to-get-the-value-of-fields-that-not-string-type/131737/2 "2018-05-14T12:54:59Z")

</div>

> i want to get field value in it's original type, like json,

JSON isn't a data type but I get what you mean.

This is a limitation in Logstash's configuration language but you can use a ruby filter to work around it.

```
event.set('location', event.get('[geoip][location]'))

```

But in this particular case, do you really want to keep the original field (and duplicate the location data)? If not then perhaps the mutate filter's rename option is what you're really looking for.

---

<div class="post-metadata">

### Author: ![floyd\_fan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/floyd_fan/32/47627_2.png) [@floyd\_fan](https://discuss.elastic.co/u/floyd_fan)
#### Post date: [May 14, 2018, 1:36pm UTC](https://discuss.elastic.co/t/how-to-get-the-value-of-fields-that-not-string-type/131737/3 "2018-05-14T13:36:20Z")

</div>

thank you for quick reply  
because in my log file, there are already country/city/region fields that thought more accuracy, so i need only lon\_lat fields in geoip  
rename option is very helpful  
I have another question: is there any significant difference between mutate filter rename option and ruby filter in effeciency？  
thank you!

---

<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: [May 14, 2018, 7:01pm UTC](https://discuss.elastic.co/t/how-to-get-the-value-of-fields-that-not-string-type/131737/4 "2018-05-14T19:01:03Z")

</div>

> is there any significant difference between mutate filter rename option and ruby filter in effeciency？

Probably not, but if that difference is important to you you should measure it.

---

<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: [June 11, 2018, 7:01pm UTC](https://discuss.elastic.co/t/how-to-get-the-value-of-fields-that-not-string-type/131737/5 "2018-06-11T19:01:08Z")

</div>

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