# Iterate through data in field logstash

**URL:** <https://discuss.elastic.co/t/iterate-through-data-in-field-logstash/272518>\
**Category:** Logstash\
**Created:** [May 9, 2021, 9:30pm UTC](https://discuss.elastic.co/t/iterate-through-data-in-field-logstash/272518 "2021-05-09T21:30:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lusynda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lusynda/32/53557_2.png) [@lusynda](https://discuss.elastic.co/u/lusynda)\
**Post date:** [May 9, 2021, 9:30pm UTC](https://discuss.elastic.co/t/iterate-through-data-in-field-logstash/272518/1 "2021-05-09T21:30:45Z")

</div>

Hi all  
I have a field like this

```auto
field: 10, 20, 30, 40

```

now that i want to make each of the data in the field to be parse like this:

```auto
field.1: 10
field.2: 20
...

```

and then use the translate plugin on each of these field.  
Can some one help me with this problems.  
also the number of data in the `field` are not always constant.

thanks

---

<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:** [May 9, 2021, 9:33pm UTC](https://discuss.elastic.co/t/iterate-through-data-in-field-logstash/272518/2 "2021-05-09T21:33:45Z")

</div>

I would use ruby. Something like

```
ruby {
    code => '
        field = event.get("field")
        if field and field.is_a? Array
            field.each_index { |x|
                event.set("field.#{x+1}", field[x])
            }
        }
    '
}
```

---

<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 6, 2021, 9:34pm UTC](https://discuss.elastic.co/t/iterate-through-data-in-field-logstash/272518/3 "2021-06-06T21:34:03Z")

</div>

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