# Fetch file name from path and append to the index name of ES

**URL:** <https://discuss.elastic.co/t/fetch-file-name-from-path-and-append-to-the-index-name-of-es/95163>\
**Category:** Logstash\
**Created:** [July 31, 2017, 9:48am UTC](https://discuss.elastic.co/t/fetch-file-name-from-path-and-append-to-the-index-name-of-es/95163 "2017-07-31T09:48:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KML](https://avatars.discourse-cdn.com/v4/letter/k/c89c15/32.png) [@KML](https://discuss.elastic.co/u/KML)\
**Post date:** [July 31, 2017, 9:48am UTC](https://discuss.elastic.co/t/fetch-file-name-from-path-and-append-to-the-index-name-of-es/95163/1 "2017-07-31T09:48:34Z")

</div>

Hello All,  
Consider that I have path field having value  
file {  
path =\> ["D:\ELK\csvs\D20150105\_R20160608.csv"]  
start\_position =\> "beginning"  
}  
So I would like to take the value 20160608 which is date YYYYMMDD varies always from the path D:\ELK\pocdocuments\csvs\D20150105\_R20160608.csv which is 8 digit value comes before .csv  
Also I need to append that value to the index name  
as index =\>stock-DD.MM.YYYY which act as timestamp value.

---

<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 2, 2017, 5:49pm UTC](https://discuss.elastic.co/t/fetch-file-name-from-path-and-append-to-the-index-name-of-es/95163/2 "2017-08-02T17:49:49Z")

</div>

Use a grok filter to extract the date from the `path` field that contains the path to the input file from which an event was read. You can then reference the field containing the date in the index option of the elasticsearch output.

---

<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:** [August 30, 2017, 5:49pm UTC](https://discuss.elastic.co/t/fetch-file-name-from-path-and-append-to-the-index-name-of-es/95163/3 "2017-08-30T17:49:54Z")

</div>

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