# Ruby code with operation (modulo)

**URL:** <https://discuss.elastic.co/t/ruby-code-with-operation-modulo/81339>\
**Category:** Logstash\
**Created:** [April 5, 2017, 4:35pm UTC](https://discuss.elastic.co/t/ruby-code-with-operation-modulo/81339 "2017-04-05T16:35:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![henrilabarre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/henrilabarre/32/16909_2.png) [@henrilabarre](https://discuss.elastic.co/u/henrilabarre)\
**Post date:** [April 5, 2017, 4:35pm UTC](https://discuss.elastic.co/t/ruby-code-with-operation-modulo/81339/1 "2017-04-05T16:35:05Z")

</div>

Hi

I use a CSV (and the logstash csv filter) and with one field I need to create a id based on this php code where $siren value is in my csv (named SIREN, for example 010441582), notice the use of php modulo (%)

```
return "FR" . (( 12 + 3 * ( $siren % 97 ) ) % 97 ) . $siren;

```

I try to do this with logstash

```
filter {

    csv {
        columns => [
			"SIREN","NIC"
        ]
        separator => ","
        }
    ruby {
		code => "
			event.set('TVA_id', (( 12 + 3 * ( event.get('SIREN') % 97 ) ) % 97 ))
			"
	     }
	mutate {
			add_field => {
			  "TVA" => "FR%{TVA_id}%{SIREN}"
			}
		}
}

```

This code failed to work, related to the code in the ruby part... If you have some clue or solution thanks in advance!

---

<div class="post-metadata">

**Author:** ![henrilabarre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/henrilabarre/32/16909_2.png) [@henrilabarre](https://discuss.elastic.co/u/henrilabarre)\
**Post date:** [April 5, 2017, 5:40pm UTC](https://discuss.elastic.co/t/ruby-code-with-operation-modulo/81339/2 "2017-04-05T17:40:45Z")

</div>

Resolve with

```
mutate {
    		convert => { "SIREN" => "integer" }
    	  }	

```

Indeed my SIREN field was a String...

---

<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:** [May 3, 2017, 5:41pm UTC](https://discuss.elastic.co/t/ruby-code-with-operation-modulo/81339/3 "2017-05-03T17:41:11Z")

</div>

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