# Template for dynamic indexes

**URL:** <https://discuss.elastic.co/t/template-for-dynamic-indexes/220134>\
**Category:** Logstash\
**Created:** [February 20, 2020, 8:58am UTC](https://discuss.elastic.co/t/template-for-dynamic-indexes/220134 "2020-02-20T08:58:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tennaen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tennaen/32/87293_2.png) [@tennaen](https://discuss.elastic.co/u/tennaen)\
**Post date:** [February 20, 2020, 8:58am UTC](https://discuss.elastic.co/t/template-for-dynamic-indexes/220134/1 "2020-02-20T08:58:53Z")

</div>

Hello,  
i have a pipeline that reads from postgres and create index for every event. It is really hard to manage which event will occur and what index will be created. Is there any way to write a template, which will be used by pipeline to create new index and assignee it to index lifecycle policy?  
Below is my pipeline configuration:

```
 input {
        jdbc {
                jdbc_driver_class => "Java::org.postgresql.Driver"
                jdbc_connection_string => "jdbc:postgresql://db_ip:5432/db_name"
                jdbc_user => "user"
                jdbc_password => "${userpass}"
                statement => "select * from T_AUDIT_LOG_EVENT where id > :sql_last_value"
                use_column_value => true
                tracking_column => id
                tracking_column_type => "numeric"
                #clean_run => true
                schedule => "* * * * *"
                last_run_metadata_path => "/u01/data/ls_logs/dev/.logstash_jdbc_last_run"
        }
 }
 filter {
        json {
                source => "value"
                target => "event"
        }
        mutate {
                add_field => {
                        "[@metadata][event_type]" => "%{[event][event_type]}"
                }
        }
        mutate {
                lowercase => ["[@metadata][event_type]"]
        }
        date {
                timezone => "Europe/Warsaw"
                match => ["[event][event_date]", "YYYY-MM-dd HH:mm:ss.SSS", "ISO8601"]
                target => "@timestamp"
        }
 }
 output {
        elasticsearch {
                hosts => "elastic_ip:9200"
                user => elasticuser
                password => "${elasticuserpass}"
                index => "dev-focus-audit-log--%{[@metadata][event_type]}"
                document_id => "%{id}"
        }
# stdout {
# codec => "rubydebug"
# }
 }
```

---

<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:** [March 19, 2020, 8:59am UTC](https://discuss.elastic.co/t/template-for-dynamic-indexes/220134/2 "2020-03-19T08:59:07Z")

</div>

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