# Dynamic index names

**URL:** <https://discuss.elastic.co/t/dynamic-index-names/268645>\
**Category:** Logstash\
**Created:** [March 29, 2021, 10:36am UTC](https://discuss.elastic.co/t/dynamic-index-names/268645 "2021-03-29T10:36:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![neilt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/neilt/32/86227_2.png) [@neilt](https://discuss.elastic.co/u/neilt)\
**Post date:** [March 29, 2021, 10:36am UTC](https://discuss.elastic.co/t/dynamic-index-names/268645/1 "2021-03-29T10:36:02Z")

</div>

I've lifted the below pattern from the logstash docs and modified for my use case.

Deffo have a field service.region in my log messages that is populated with values dev1 dev2 or sit. But i am not seeing the indexes with [service][region] pattern being created.

Looking at debug logs it seems that my if statement seems always to drop to else clause .

Using ELK 7.12.0

What am I doing wrong ?

```auto
filter {
# we don't want these to go to the application log indexes
    if [service][region] in ["dev1","dev2","sit"] {
        mutate {
            add_field => { "[@metadata][target_index]" => "blade-logs-%{[service][region]}-%{+YYYY.MM.dd}" }
        }
    } else {
        mutate {
            add_field => { "[@metadata][target_index]" => "blade-logs-%{+YYYY.MM.dd}" } }
    }
    mutate {
        rename => {
            "message.index" => "message_index"
        }
    }
}

```

foo

```auto
output {
    elasticsearch {
        ....
        index => "%{[@metadata][target_index]}"
        ilm_enabled => false
    }
}

```

I get the logic around ILM managed indexes and naming as mentioned in previous answers.

---

<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:** [April 26, 2021, 10:50am UTC](https://discuss.elastic.co/t/dynamic-index-names/268645/3 "2021-04-26T10:50:32Z")

</div>

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