# Ruby filter, load csv file to add field

**URL:** <https://discuss.elastic.co/t/ruby-filter-load-csv-file-to-add-field/44322>\
**Category:** Logstash\
**Created:** [March 14, 2016, 12:12pm UTC](https://discuss.elastic.co/t/ruby-filter-load-csv-file-to-add-field/44322 "2016-03-14T12:12:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![patou](https://avatars.discourse-cdn.com/v4/letter/p/f475e1/32.png) [@patou](https://discuss.elastic.co/u/patou)\
**Post date:** [March 14, 2016, 12:12pm UTC](https://discuss.elastic.co/t/ruby-filter-load-csv-file-to-add-field/44322/1 "2016-03-14T12:12:45Z")

</div>

hi,

i need to load a csv file in a ruby filter to add fields to the document.  
will the csv file be loaded for each line of the input or only once ?

cdt  
patrick

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [March 15, 2016, 4:52am UTC](https://discuss.elastic.co/t/ruby-filter-load-csv-file-to-add-field/44322/2 "2016-03-15T04:52:48Z")

</div>

Each event/line.

---

<div class="post-metadata">

**Author:** ![wiibaa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wiibaa/32/44931_2.png) [@wiibaa](https://discuss.elastic.co/u/wiibaa)\
**Post date:** [March 16, 2016, 11:23am UTC](https://discuss.elastic.co/t/ruby-filter-load-csv-file-to-add-field/44322/3 "2016-03-16T11:23:34Z")

</div>

Please have a look into the ruby filter documentation and assess if it is possible for you to load your csv in the `init => ""` config of the filter to load it only once.

And did you have a look in the translate filter [https://www.elastic.co/guide/en/logstash/current/plugins-filters-translate.html](https://www.elastic.co/guide/en/logstash/current/plugins-filters-translate.html) that might suits your usecase

---

<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, 5:06am UTC](https://discuss.elastic.co/t/ruby-filter-load-csv-file-to-add-field/44322/4 "2017-07-06T05:06:46Z")

</div>


