# Can not re-use field value for calculating new value

**URL:** <https://discuss.elastic.co/t/can-not-re-use-field-value-for-calculating-new-value/160931>\
**Category:** Logstash\
**Created:** [December 14, 2018, 3:23pm UTC](https://discuss.elastic.co/t/can-not-re-use-field-value-for-calculating-new-value/160931 "2018-12-14T15:23:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hryhorii\_Koval](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hryhorii_koval/32/38840_2.png) [@Hryhorii\_Koval](https://discuss.elastic.co/u/Hryhorii_Koval)\
**Post date:** [December 14, 2018, 3:23pm UTC](https://discuss.elastic.co/t/can-not-re-use-field-value-for-calculating-new-value/160931/1 "2018-12-14T15:23:14Z")

</div>

Depends on some condition I want to re-calculate field value. Please, give me a hand.

ruby {  
code =\> "event.set('my\_field', event.get('my\_field')\*1024)"  
}

---

<div class="post-metadata">

**Author:** ![AquaX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aquax/32/92006_2.png) [@AquaX](https://discuss.elastic.co/u/AquaX)\
**Post date:** [December 16, 2018, 1:37am UTC](https://discuss.elastic.co/t/can-not-re-use-field-value-for-calculating-new-value/160931/2 "2018-12-16T01:37:35Z")

</div>

If that’s not working then use a temporary variable that you remove after you’re done calculating.

Event.set(‘my\_field’, ‘temp’); Event.set(‘my\_field’, event.get(‘temp’)\*1024);

remove\_field =\> “temp”

---

<div class="post-metadata">

**Author:** ![Hryhorii\_Koval](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hryhorii_koval/32/38840_2.png) [@Hryhorii\_Koval](https://discuss.elastic.co/u/Hryhorii_Koval)\
**Post date:** [December 19, 2018, 10:07am UTC](https://discuss.elastic.co/t/can-not-re-use-field-value-for-calculating-new-value/160931/3 "2018-12-19T10:07:40Z")

</div>

Hi. I've resolved this issue. You gave me a good prompt ))

if [@metadata][csv][Flag] == "1" {  
ruby {  
init =\> "@var\_tmp"  
code =\> "  
event.set('var\_tmp', event.get('my\_field'))  
event.set('my\_field', event.get(''var\_tmp')\*1024);"  
}  
}

And in the end we need to remove this temporary variable.

mutate {  
remove\_field =\> ["var\_tmp"]  
}

Guys, but not forget firstly to convert type of your field to some numeric ones!

---

<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:** [January 16, 2019, 10:07am UTC](https://discuss.elastic.co/t/can-not-re-use-field-value-for-calculating-new-value/160931/4 "2019-01-16T10:07:43Z")

</div>

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