# Get specific fields from csv file

**URL:** <https://discuss.elastic.co/t/get-specific-fields-from-csv-file/134200>\
**Category:** Logstash\
**Created:** [June 1, 2018, 10:33am UTC](https://discuss.elastic.co/t/get-specific-fields-from-csv-file/134200 "2018-06-01T10:33:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kingprakatheesh](https://avatars.discourse-cdn.com/v4/letter/k/aeb1de/32.png) [@kingprakatheesh](https://discuss.elastic.co/u/kingprakatheesh)\
**Post date:** [June 1, 2018, 10:33am UTC](https://discuss.elastic.co/t/get-specific-fields-from-csv-file/134200/1 "2018-06-01T10:33:04Z")

</div>

i am haing a csv file having 100 fields. i want to parse only 5 fields so i used Ruby filter and framed my conf. Upon executing getting {} in all lines instead of fields

Conf file

input{  
file {  
path =\> path\_to\_file  
start\_position =\> "beginning"  
sincedb\_path =\> "/dev/null"  
}  
}  
filter {  
ruby {  
code =\> "  
wanted\_fields = ['','']  
event.to\_hash.keys.each { |k|  
event.remove(k) unless wanted\_fields.include? k  
}  
"  
}  
}  
output  
{  
stdout{}  
}

Output:

{}  
{}  
{}  
{}  
{}

Thanks in advance

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [June 1, 2018, 11:16am UTC](https://discuss.elastic.co/t/get-specific-fields-from-csv-file/134200/2 "2018-06-01T11:16:39Z")

</div>

I suggest you use the prune filter for this.

---

<div class="post-metadata">

**Author:** ![dyl](https://avatars.discourse-cdn.com/v4/letter/d/5fc32e/32.png) [@dyl](https://discuss.elastic.co/u/dyl)\
**Post date:** [June 1, 2018, 12:06pm UTC](https://discuss.elastic.co/t/get-specific-fields-from-csv-file/134200/3 "2018-06-01T12:06:56Z")

</div>

You can parse your CSV with ["CSV"](https://www.elastic.co/guide/en/logstash/current/plugins-filters-csv.html#plugins-filters-csv) filter option and then you can use "[remove\_field](https://www.elastic.co/guide/en/logstash/current/plugins-filters-csv.html#plugins-filters-csv-remove_field)" to remove undesirable fields

---

<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 29, 2018, 12:07pm UTC](https://discuss.elastic.co/t/get-specific-fields-from-csv-file/134200/4 "2018-06-29T12:07:00Z")

</div>

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