Create or update a legacy index template Deprecated Generally available
All methods and paths for this operation:
Index templates define settings, mappings, and aliases that can be applied automatically to new indices. Elasticsearch applies templates to new indices based on an index pattern that matches the index name.
IMPORTANT: This documentation is about legacy index templates, which are deprecated and will be replaced by the composable templates introduced in Elasticsearch 7.8.
Composable templates always take precedence over legacy templates. If no composable template matches a new index, matching legacy templates are applied according to their order.
Index templates are only applied during index creation. Changes to index templates do not affect existing indices. Settings and mappings specified in create index API requests override any settings or mappings specified in an index template.
You can use C-style /* *\/
block comments in index templates. You can include comments anywhere in the request body, except before the opening curly bracket.
Indices matching multiple templates
Multiple index templates can potentially match an index, in this case, both the settings and mappings are merged into the final configuration of the index. The order of the merging can be controlled using the order parameter, with lower order being applied first, and higher orders overriding them. NOTE: Multiple matching templates with the same order value will result in a non-deterministic merging order.
Required authorization
- Cluster privileges:
manage_index_templates
,manage
Query parameters
-
If true, this request cannot replace or update existing index templates.
-
Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error.
Values are
-1
or0
. -
Order in which Elasticsearch applies this template if index matches multiple templates.
Templates with lower 'order' values are merged first. Templates with higher 'order' values are merged later, overriding templates with lower values.
-
User defined reason for creating/updating the index template
Body Required
-
Aliases for the index.
-
Order in which Elasticsearch applies this template if index matches multiple templates.
Templates with lower 'order' values are merged first. Templates with higher 'order' values are merged later, overriding templates with lower values.
-
Index settings
PUT _template/template_1 { "index_patterns": [ "te*", "bar*" ], "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" } } }
resp = client.indices.put_template( name="template_1", index_patterns=[ "te*", "bar*" ], 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" } }, )
const response = await client.indices.putTemplate({ name: "template_1", index_patterns: ["te*", "bar*"], 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", }, }, });
response = client.indices.put_template( name: "template_1", body: { "index_patterns": [ "te*", "bar*" ], "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" } } } )
$resp = $client->indices()->putTemplate([ "name" => "template_1", "body" => [ "index_patterns" => array( "te*", "bar*", ), "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", ], ], ], ]);
curl -X PUT -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"index_patterns":["te*","bar*"],"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"}}}' "$ELASTICSEARCH_URL/_template/template_1"
client.indices().putTemplate(p -> p .indexPatterns(List.of("te*","bar*")) .mappings(m -> m .source(s -> s .enabled(false) ) ) .name("template_1") .settings(s -> s .numberOfShards("1") ) );
{ "index_patterns": [ "te*", "bar*" ], "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" } } }
{ "index_patterns": [ "te*" ], "settings": { "number_of_shards": 1 }, "aliases": { "alias1": {}, "alias2": { "filter": { "term": { "user.id": "kimchy" } }, "routing": "shard-1" }, "{index}-alias": {} } }