| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 | [[index-templates]]= Index templatesNOTE: This topic describes the composable index templates introduced in {es} 7.8. For information about how index templates worked previously, see the <<indices-templates-v1,legacy template documentation>>.[[getting]]An index template is a way to tell {es} how to configure an index when it is created.For data streams, the index template configures the stream's backing indices as theyare created. Templates are configured prior to index creation and then when anindex is created either manually or through indexing a document, the templatesettings are used as a basis for creating the index.There are two types of templates, index templates and <<indices-component-template,componenttemplates>>. Component templates are reusable building blocks that configure mappings, settings, andaliases. You use component templates to construct index templates, they aren't directly applied to aset of indices. Index templates can contain a collection of component templates, as well as directlyspecify settings, mappings, and aliases.If a new data stream or index matches more than one index template, the index template with the highest priority is used.[IMPORTANT]===={es} has built-in index templates for the `metrics-*-*` and `logs-*-*` indexpatterns, each with a priority of `100`.{ingest-guide}/ingest-management-overview.html[{agent}] uses these templates tocreate data streams. If you use {agent}, assign your index templates a prioritylower than `100` to avoid an overriding the built-in templates.Otherwise, to avoid accidentally applying the built-in templates, use anon-overlapping index pattern or assign templates with an overlapping pattern a`priority` higher than `100`.For example, if you don't use {agent} and want to create a template for the`logs-*` index pattern, assign your template a priority of `200`. This ensuresyour template is applied instead of the built-in template for `logs-*-*`.====When a composable template matches a given indexit always takes precedence over a legacy template. If no composable template matches, a legacytemplate may still match and be applied.If an index is created with explicit settings and also matches an index template,the settings from the create index request take precedence over settings specified in the index template and its component templates.[source,console]--------------------------------------------------PUT _component_template/component_template1{  "template": {    "mappings": {      "properties": {        "@timestamp": {          "type": "date"        }      }    }  }}PUT _component_template/other_component_template{  "template": {    "mappings": {      "properties": {        "ip_address": {          "type": "ip"        }      }    }  }}PUT _index_template/template_1{  "index_patterns": ["te*", "bar*"],  "template": {    "settings": {      "number_of_shards": 1    },    "mappings": {      "_source": {        "enabled": false      },      "properties": {        "host_name": {          "type": "keyword"        },        "created_at": {          "type": "date",          "format": "EEE MMM dd HH:mm:ss Z yyyy"        }      }    },    "aliases": {      "mydata": { }    }  },  "priority": 200,  "composed_of": ["component_template1", "other_component_template"],  "version": 3,  "_meta": {    "description": "my custom"  }}--------------------------------------------------// TESTSETUP////[source,console]--------------------------------------------------DELETE _index_template/*DELETE _component_template/*--------------------------------------------------// TEARDOWN////include::simulate-multi-component-templates.asciidoc[]
 |