# Need some help with Ruby event.set / get to use multiplication in config

**URL:** <https://discuss.elastic.co/t/need-some-help-with-ruby-event-set-get-to-use-multiplication-in-config/165042>\
**Category:** Logstash\
**Created:** [January 21, 2019, 11:51am UTC](https://discuss.elastic.co/t/need-some-help-with-ruby-event-set-get-to-use-multiplication-in-config/165042 "2019-01-21T11:51:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Datakids](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/datakids/32/39622_2.png) [@Datakids](https://discuss.elastic.co/u/Datakids)\
**Post date:** [January 21, 2019, 11:51am UTC](https://discuss.elastic.co/t/need-some-help-with-ruby-event-set-get-to-use-multiplication-in-config/165042/1 "2019-01-21T11:51:02Z")

</div>

Currency and Gross\_Value are existing fields:

```
mutate { 
add_field => {"Gross_Euro" => "" }}
mutate {
convert => { "Gross_Euro" => "float" }}
if "INR" in [Currency] {
ruby { code => "event ['Gross_Euro'] = event['Gross_Value'] * 0,01221"} }

```

With above I get a [0] "\_rubyexception"

[2019-01-21T12:07:30,690][ERROR][logstash.filters.ruby] Ruby exception occurred: Direct event field references (i.e. event['field']) have been disabled in favor of using event get and set methods (e.g. event.get('field')). Please consult the Logstash 5.0 breaking changes documentation for more details.

Ahh ok try this:

```
if "INR" in [Currency] {
	    ruby {
			"event.set ('[Gross_Euro]' = event.get('[Gross_Value]' * 0,01221))"
		}
}

```

and this:

```
if "INR" in [Currency] {
	    ruby {
			"event.set ('[Gross_Euro]' = event.get('[Gross_Value]') * 0,01221)"
		}
}

```

and this:

```
if "INR" in [Currency] {
	    ruby {
			"event.set ('[Gross_Euro]') = event.get('[Gross_Value]') * 0,01221"
		}
}

```

nope !

I now something is wrong but dunno what exactly.

Thanks for any hint

Regards

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [January 21, 2019, 12:50pm UTC](https://discuss.elastic.co/t/need-some-help-with-ruby-event-set-get-to-use-multiplication-in-config/165042/2 "2019-01-21T12:50:43Z")

</div>

The syntax [is](https://www.elastic.co/guide/en/logstash/current/event-api.html)

```
 event.set("fieldname", "fieldvalue")

```

Also, you will need to use 0.1221 instead of 0,1221. And it might need a .to\_f in there as well.

---

<div class="post-metadata">

**Author:** ![Datakids](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/datakids/32/39622_2.png) [@Datakids](https://discuss.elastic.co/u/Datakids)\
**Post date:** [January 21, 2019, 1:43pm UTC](https://discuss.elastic.co/t/need-some-help-with-ruby-event-set-get-to-use-multiplication-in-config/165042/3 "2019-01-21T13:43:02Z")

</div>

Thanks for reply, that pushed me to investigate a bit deeper 🙂  
I did a few different syntaxes and then found one that fits to my needs:

My first mistake: I forget "code =\>" in front of "event" and finaly used following expression.

```
if "INR" in [Currency]{
	    ruby {
			code => "event.set('Gross_Euro', event.get('Gross_Value') * 0.01221)"
		}	
} 

```

Here wo go  
Nice day to you

---

<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:** [February 18, 2019, 1:43pm UTC](https://discuss.elastic.co/t/need-some-help-with-ruby-event-set-get-to-use-multiplication-in-config/165042/4 "2019-02-18T13:43:03Z")

</div>

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