# Trying to add fields to CSV and fill them with data

**URL:** <https://discuss.elastic.co/t/trying-to-add-fields-to-csv-and-fill-them-with-data/95952>\
**Category:** Logstash\
**Created:** [August 4, 2017, 8:37pm UTC](https://discuss.elastic.co/t/trying-to-add-fields-to-csv-and-fill-them-with-data/95952 "2017-08-04T20:37:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dorj1234](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dorj1234/32/21339_2.png) [@dorj1234](https://discuss.elastic.co/u/dorj1234)\
**Post date:** [August 4, 2017, 8:37pm UTC](https://discuss.elastic.co/t/trying-to-add-fields-to-csv-and-fill-them-with-data/95952/1 "2017-08-04T20:37:29Z")

</div>

Hi and thanks for reading and helping. Posting because my search got nothing I can use.  
I am uploading .csv files from a directory structure that represents countries.  
The filenames don't give me anything but the date.  
Example:

/path/to/france/file\_01012017.csv  
/path/to/germany/file\_01022017.csv

I would like to:

1. Use "france" as the index for example  
index =\> "logstash\_france\_%{datetime}"
2. Add a column to the output and put "france" in it for all the records

I tried to understand how to use add\_field or something similar, but would appreciate any advice.

Thanks !  
JD

---

<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:** [August 5, 2017, 4:10pm UTC](https://discuss.elastic.co/t/trying-to-add-fields-to-csv-and-fill-them-with-data/95952/2 "2017-08-05T16:10:28Z")

</div>

Use a grok filter to parse the `path` field which contains the whole file path. Store the directory component containing the country in a field that you then reference in the output configuration.

---

<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:** [September 2, 2017, 4:10pm UTC](https://discuss.elastic.co/t/trying-to-add-fields-to-csv-and-fill-them-with-data/95952/3 "2017-09-02T16:10:36Z")

</div>

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