# How to Apply Custom Template to Logstash (8.x)

**URL:** <https://discuss.elastic.co/t/how-to-apply-custom-template-to-logstash-8-x/341110>\
**Category:** Logstash\
**Tags:** docker\
**Created:** [August 18, 2023, 4:41pm UTC](https://discuss.elastic.co/t/how-to-apply-custom-template-to-logstash-8-x/341110 "2023-08-18T16:41:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![inkweon7269](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/inkweon7269/32/124738_2.png) [@inkweon7269](https://discuss.elastic.co/u/inkweon7269)\
**Post date:** [August 18, 2023, 4:41pm UTC](https://discuss.elastic.co/t/how-to-apply-custom-template-to-logstash-8-x/341110/1 "2023-08-18T16:41:39Z")

</div>

I am studying Elasticsearch using Docker Compose and ELK. I am having an issue where the custom template is not being applied in logstash.conf. How can I fixed it?

### csv-template.json

```auto
{
  "template": "csv",
  "order": "1",
  "settings": {
    "refresh_interval": "5s"
  },
  "mappings": {
    "properties": {
      "age": {
        "type": "double"
      },
      "name": {
        "type": "keyword"
      },
      "skill": {
        "type": "keyword"
      },
      "city": {
        "type": "keyword"
      }
    }
  }
}

```

### file.csv

```auto
name,age,skill,city
Kim,100,JavaScript,Seoul
Park,200,Python,Busan
Lee,300,Java,Incheon

```

### logstash.conf

```auto
input {
    beats {
        port => 5044
    }
    tcp {
        port => 50000
    }
    file {
        path => "/usr/share/logstash/input/file.csv"
        start_position => "beginning"
        sincedb_path => "NUL"
    }
}

filter {
    csv {
        separator => ","
        skip_header => "true"
        columns => ["name", "age", "skill", "city"]
    }
    mutate {
        remove_field => ["message", "@timestamp", "host", "@version"]
    }
}

output {
    elasticsearch {
        hosts => "elasticsearch:9200"
        user => "elastic"
        password => "${LOGSTASH_INTERNAL_PASSWORD}"
        index => "csv"
        manage_template => true
        template => '/usr/share/logstash/config/csv-template.json'
        template_name => "csv"
        template_overwrite => true
    }
    stdout {
        codec => "rubydebug"
    }
}

```

### docker-compse.yml

```auto
version: '3.7'
......
  logstash:
    build:
      context: logstash/
      args:
        ELASTIC_VERSION: ${ELASTIC_VERSION}
    volumes:
      - ./logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml:ro,Z
      - ./logstash/config/csv-template.json:/usr/share/logstash/config/csv-template.json:ro,Z
      - ./logstash/pipeline:/usr/share/logstash/pipeline:ro,Z
      - ./logstash/input:/usr/share/logstash/input:ro,Z
      - ./logstash/jar/postgresql-42.6.0.jar:/usr/share/logstash/postgresql.jar
......

```

### Result

 ![스크린샷 2023-08-19 오전 12.38.44](https://us1.discourse-cdn.com/elastic/original/3X/9/0/90bb068ea0c8885517eb3ef2fa780517c44657df.png)

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [August 18, 2023, 9:25pm UTC](https://discuss.elastic.co/t/how-to-apply-custom-template-to-logstash-8-x/341110/2 "2023-08-18T21:25:35Z")

</div>

Hi @inkweon7269 Welcome to the community.

What version are you using?

You need to set the index patterns something like this shown [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-templates.html#create-index-templates) this is example

` "index_patterns": ["csv", "csv-*"],`

Otherwise the template won't match the index being created... That's how the template gets applied

---

<div class="post-metadata">

**Author:** ![inkweon7269](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/inkweon7269/32/124738_2.png) [@inkweon7269](https://discuss.elastic.co/u/inkweon7269)\
**Post date:** [August 18, 2023, 11:25pm UTC](https://discuss.elastic.co/t/how-to-apply-custom-template-to-logstash-8-x/341110/3 "2023-08-18T23:25:31Z")

</div>

Please respond. Thank you. We are using all versions as 8.x. (Elasticsearch, logstash, kibana)

I accessed the link you provided and made the changes, and it's working properly now. Thank you!

---

<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:** [September 15, 2023, 11:25pm UTC](https://discuss.elastic.co/t/how-to-apply-custom-template-to-logstash-8-x/341110/4 "2023-09-15T23:25:58Z")

</div>

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