# Is it possible to create multiple index with multiple folder name

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-create-multiple-index-with-multiple-folder-name/321457>\
**Category:** Logstash\
**Created:** [December 17, 2022, 3:35pm UTC](https://discuss.elastic.co/t/is-it-possible-to-create-multiple-index-with-multiple-folder-name/321457 "2022-12-17T15:35:23Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Rios](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rios/32/95745_2.png) [@Rios](https://discuss.elastic.co/u/Rios)\
**Post date:** [December 17, 2022, 4:49pm UTC](https://discuss.elastic.co/t/is-it-possible-to-create-multiple-index-with-multiple-folder-name/321457/2 "2022-12-17T16:49:27Z")

</div>

Yes, it is possible. Use gsub to extract folder name, then add in [@metadata][dir]  
The best is to provide with dir name samples.

```auto
output {
   elasticsearch {
    hosts => ["http://localhost:9200"]
    index => "indexname_%{[@metadata][dir]}"
   } 
}

```

Other possibly is to set with IFs which is more strict and more usable in some cases.

```auto
output {
 if ([@metadata][dir]=="dir1"){
   elasticsearch {
    hosts => ["http://localhost:9200"]
    index => "indexname_%{[@metadata][dir]}"
   } 
 }
 else if ([@metadata][dir]=="dir2"){
    elasticsearch {
    hosts => ["http://localhost:9200"]
    index => "indexname_%{[@metadata][dir]}"
   } 
 }
 else if ([@metadata][dir]=="dir3"){
    elasticsearch {
    hosts => ["http://localhost:9200"]
    index => "indexname_%{[@metadata][dir]}"
   } 
 }

```

---

_[View the full topic](https://discuss.elastic.co/t/is-it-possible-to-create-multiple-index-with-multiple-folder-name/321457)._
