# Dynamic index name

**URL:** <https://discuss.elastic.co/t/dynamic-index-name/2490>\
**Category:** Logstash\
**Created:** [June 11, 2015, 3:30pm UTC](https://discuss.elastic.co/t/dynamic-index-name/2490 "2015-06-11T15:30:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![maran](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@maran](https://discuss.elastic.co/u/maran)\
**Post date:** [June 11, 2015, 3:30pm UTC](https://discuss.elastic.co/t/dynamic-index-name/2490/1 "2015-06-11T15:30:53Z")

</div>

Hi!

I'm trying to dynamically set index names with if-cases in my logstash.conf file. Basically if file name is A then indexname should be A. But for some reason my variable (type) is not set or accessible when I get to the output section leaving me with an index name like : %{type}-2015-05-10

What am I doing wrong?

This is my config:

```
   input {
        file {
                path => "/somefolder/*.log"
                 start_position => beginning
                    sincedb_path => "somfilelocation"
            } 
    }
    
        filter {
            if [path] = condition_a {
            mutate { replace => { "type" => "ToBeIndexName" } }
        }

        elseif [path] = condition_b {
        mutate { replace => { "type" => "ToBeIndexName" } }

        } 

    Some parsing 

 

       output {
                elasticsearch {
                                index => "%{type}-%{+YYYY.MM.dd}"
                        }
    }
```

---

<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 11, 2015, 5:57pm UTC](https://discuss.elastic.co/t/dynamic-index-name/2490/2 "2015-06-11T17:57:15Z")

</div>

Start by using `==` as the equality operator instead of `=`. If that doesn't help I reckon it boils down to exactly what your conditionals look like, but as long as they're obfuscated we can't really help you.

---

<div class="post-metadata">

**Author:** ![Sushil\_Kumar](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@Sushil\_Kumar](https://discuss.elastic.co/u/Sushil_Kumar)\
**Post date:** [June 1, 2017, 10:23am UTC](https://discuss.elastic.co/t/dynamic-index-name/2490/3 "2017-06-01T10:23:54Z")

</div>

Hi There, I am using below configuration file but index is not replaced.

input { file {  
path =\> "inp\_file.txt"  
start\_position =\> "beginning"  
}  
}

filter {

grok {  
patterns\_dir =\> ["./diag\_patterns"]  
match =\> { "message" =\> "%{GET\_CPE\_ID:cpe\_id}" } } /_this is fetching a number_/  
}

output {  
elasticsearch {  
hosts =\> ["localhost:9200"]  
index =\> "%{cpe\_id}" /_This is not getting replaced_/  
}  
stdout { codec =\> json }  
}

json outfrom stdout is  
{"path":"C:\Users\sushiku2\Downloads\ELK\Practice\_Learn\_ELK\DIAG\_sample2.txt","@timestamp":"2017-06-01T10:02:59.296Z","@version":"1","host":"SUSHIKU2-MNFSN","cpe\_id":"1638916117","message":"801998 !MIL -SPM\_SERVER \t\t\< p:0x00000612 P:MW t:0x02e49500 T:SPM\_THREAD M:spm\_ps.c F:SPM\_PS\_FillRequestParametersVOO L:3038 \> Real CPE\_ID=1638916117, Network ID=1320, HDDId=WD-WXC1A63N2060, First install=false","tags":["\_grokparsefailure"]}

---

<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, 2017, 1:08pm UTC](https://discuss.elastic.co/t/dynamic-index-name/2490/4 "2017-06-01T13:08:43Z")

</div>

@Sushil_Kumar, please start new threads for new questions.

---

<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:** [July 6, 2017, 4:26am UTC](https://discuss.elastic.co/t/dynamic-index-name/2490/5 "2017-07-06T04:26:07Z")

</div>


