# Index creation based on file name

**URL:** https://discuss.elastic.co/t/index-creation-based-on-file-name/101307
**Category:** Logstash
**Created:** [September 21, 2017, 10:13am UTC](https://discuss.elastic.co/t/index-creation-based-on-file-name/101307 "2017-09-21T10:13:38Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![DILIP\_SHARMA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dilip_sharma/32/42672_2.png) [@DILIP\_SHARMA](https://discuss.elastic.co/u/DILIP_SHARMA)
#### Post date: [September 21, 2017, 10:13am UTC](https://discuss.elastic.co/t/index-creation-based-on-file-name/101307/1 "2017-09-21T10:13:39Z")

</div>

Hi All  
i want to create dynamic index based on the file name --  
currently my input part is -

> input {  
> file {  
> path =\> "E:\Local\_Elasticsearch\logstashv5\datafiles/\*.csv"  
> start\_position =\> "beginning"
> 
> }  
> }

and my output part is -

```
output {
	elasticsearch {
		hosts => "localhost"
		index => "testindex1"
		document_type => "tesdata1"
	}
	stdout{}

}

```

how can i have index name based on file is uploading from data folder ..  
any help or suggestion .

Thanks

---

<div class="post-metadata">

### Author: ![DILIP\_SHARMA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dilip_sharma/32/42672_2.png) [@DILIP\_SHARMA](https://discuss.elastic.co/u/DILIP_SHARMA)
#### Post date: [September 21, 2017, 10:51am UTC](https://discuss.elastic.co/t/index-creation-based-on-file-name/101307/2 "2017-09-21T10:51:51Z")

</div>

i used index =\> "logstash-%{+YYYYMMdd}" this method to solve my issue .  
Thanks

---

<div class="post-metadata">

### Author: ![paz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paz/32/28003_2.png) [@paz](https://discuss.elastic.co/u/paz)
#### Post date: [September 21, 2017, 10:57am UTC](https://discuss.elastic.co/t/index-creation-based-on-file-name/101307/3 "2017-09-21T10:57:39Z")

</div>

What you've posted does not create indices based on filename, but rather daily indices.

If you still want filename-based indexing, you can use the "path" field of each event, like so

```auto
filter {
        ruby {
            code => "
                event.set('index_name',event.get('path').split('/')[-1].gsub('.csv',''))
            "
        }
}
output {
	elasticsearch {
		hosts => "localhost"
		index => "%{index_name}"
		document_type => "tesdata1"
	}
}
```

---

<div class="post-metadata">

### Author: ![DILIP\_SHARMA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dilip_sharma/32/42672_2.png) [@DILIP\_SHARMA](https://discuss.elastic.co/u/DILIP_SHARMA)
#### Post date: [September 21, 2017, 4:36pm UTC](https://discuss.elastic.co/t/index-creation-based-on-file-name/101307/4 "2017-09-21T16:36:46Z")

</div>

yes , but that solved my problem, i m ok with daily index . but still thanks a lot for this solution i will use that somewhere .

thanks  
Dilip

---

<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: [October 19, 2017, 4:36pm UTC](https://discuss.elastic.co/t/index-creation-based-on-file-name/101307/5 "2017-10-19T16:36:59Z")

</div>

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