Matching templates with indices

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

{
  "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?

    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
    }
   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
    }

@pkaramol
why not have two templates but 1. match bar_* and 2. match foo_*

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

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

1 Like

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