# Ruby code in filter does not executed in sequence

**URL:** <https://discuss.elastic.co/t/ruby-code-in-filter-does-not-executed-in-sequence/55622>\
**Category:** Logstash\
**Created:** [July 15, 2016, 1:23pm UTC](https://discuss.elastic.co/t/ruby-code-in-filter-does-not-executed-in-sequence/55622 "2016-07-15T13:23:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![OlivierD](https://avatars.discourse-cdn.com/v4/letter/o/ac8455/32.png) [@OlivierD](https://discuss.elastic.co/u/OlivierD)\
**Post date:** [July 15, 2016, 1:23pm UTC](https://discuss.elastic.co/t/ruby-code-in-filter-does-not-executed-in-sequence/55622/1 "2016-07-15T13:23:45Z")

</div>

I have an input CSV file that I want to parse with logstash. I want to maintain a variable across events loaded from the file, using a variable in the Ruby code.

I have an issue so I write a simple CSV input file and a simple logstash.conf file as follow:

The **csv file** contains only 1 column with a sequence of number:  
1  
2  
3  
...  
999

**logstash.conf:**

```
filter 
{  
    csv 
	{
        	columns => ["line"]
	}
	ruby
	{
		init => 
		"			
			@i = 0
		" 
		code => 
		"
			@i = @i + 1
			event['i'] = @i
		"
	}
}
output 
{  
	stdout 
	{
       	codec => rubydebug
    }
}

```

When I execute logstash, I see that few events are not in the good order;for example:

"message" =\> "62",  
"line" =\> "62",  
"i" =\> **91**

I do not understand the reason, so I could not use a variable in the Ruby code to maintain a context between 2 successive events (with a same property).

Do you have any idea ?

---

<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:** [July 6, 2017, 4:47am UTC](https://discuss.elastic.co/t/ruby-code-in-filter-does-not-executed-in-sequence/55622/2 "2017-07-06T04:47:50Z")

</div>


