# Matching templates with indices

**URL:** https://discuss.elastic.co/t/matching-templates-with-indices/132460
**Category:** Logstash
**Created:** [May 18, 2018, 10:11am UTC](https://discuss.elastic.co/t/matching-templates-with-indices/132460 "2018-05-18T10:11:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![pkaramol](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pkaramol/32/22610_2.png) [@pkaramol](https://discuss.elastic.co/u/pkaramol)
#### Post date: [May 18, 2018, 10:11am UTC](https://discuss.elastic.co/t/matching-templates-with-indices/132460/1 "2018-05-18T10:11:10Z")

</div>

Can we use wildcards when we want a specific template to be applied in several indices?

e.g. is the following applicable?

this is from a template file, say `my_template_file.json`

```auto
{
  "order": 1,
  "index_patterns": "*mapping_channels*",
  "settings": {
    "index": {
      "number_of_shards": "3",
      "number_of_replicas": "1"
    }
  },
  "mappings": {
    "_doc": {
      "properties": {
        "username" : { "type" : "keyword" },
        "someip": {"type": "ip"},
      }
    }
  }
}

```

Will then the above template be applied to **BOTH** the following `elasticsearch` outputs?

```auto
    elasticsearch {
      hosts => ["elasticsearch:9200"]
      index => "bar_mapping_channels_foo"
      document_id => "%{[@metadata][custom_id]}"
      template => "/path/to/my_template_file.json"
      template_name => "mapping_channels_template"
      manage_template => true
      template_overwrite => true
      document_type => _doc
    }

```

```auto
   elasticsearch {
      hosts => ["elasticsearch:9200"]
      index => "foo_mapping_channels_bar"
      document_id => "%{[@metadata][custom_id]}"
      template => "/path/to/my_template_file.json"
      template_name => "mapping_channels_template"
      manage_template => true
      template_overwrite => true
      document_type => _doc
    }

```

---

<div class="post-metadata">

### Author: ![JKhondhu](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@JKhondhu](https://discuss.elastic.co/u/JKhondhu)
#### Post date: [May 18, 2018, 11:40am UTC](https://discuss.elastic.co/t/matching-templates-with-indices/132460/2 "2018-05-18T11:40:37Z")

</div>

@pkaramol  
why not have two templates but 1. match bar\_\* and 2. match foo\_\*

---

<div class="post-metadata">

### Author: ![RRSR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rrsr/32/27766_2.png) [@RRSR](https://discuss.elastic.co/u/RRSR)
#### Post date: [May 18, 2018, 11:46am UTC](https://discuss.elastic.co/t/matching-templates-with-indices/132460/3 "2018-05-18T11:46:36Z")

</div>

> [@pkaramol](#):
>
> Can we use wildcards when we want a specific template to be applied in several indices?

Yes, you can use a wildcard when you want the template to be applied to multiple indices.

> [@pkaramol](#):
>
> Will then the above template be applied to BOTH the following elasticsearch outputs?

Yes, the above template will be applied to both the indices as both the indices(`bar_mapping_channels_foo` & `foo_mapping_channe'ls_bar`) matches your index pattern `*mapping_channels*`.  
Reference : [Index Templates](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html)

---

<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: [June 15, 2018, 11:46am UTC](https://discuss.elastic.co/t/matching-templates-with-indices/132460/4 "2018-06-15T11:46:37Z")

</div>

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