Simulate index template API
editSimulate index template API
editReturns the index configuration that would be applied by a particular index template.
POST /_index_template/_simulate/template_1
Request
editPOST /_index_template/_simulate/<index-template>
Prerequisites
edit-
If the Elasticsearch security features are enabled, you must have the
manage_index_templates
ormanage
cluster privilege to use this API.
Path parameters
edit-
<index-template>
- (Optional, string) Name of the index template to simulate. To test a template configuration before you add it to the cluster, omit this parameter and specify the template configuration in the request body.
Query parameters
edit-
create
-
(Optional, Boolean) If
true
, the template passed in the body is only used if no existing templates match the same index patterns. Iffalse
, the simulation uses the template with the highest priority. Note that the template is not permanently added or updated in either case; it is only used for the simulation. Defaults tofalse
. -
master_timeout
-
(Optional, time units)
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. Defaults to
30s
. -
include_defaults
-
(Optional, Boolean) Functionality in
[preview]
This functionality is in technical preview and may be changed or removed in a future release. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features.
. If
true
, return all default settings in the response. Defaults tofalse
.
Request body
edit-
data_stream
-
(Optional, object) If this object is included, the template is used to create data streams and their backing indices. Supports an empty object.
Data streams require a matching index template with a
data_stream
object. See create an index template.Properties of
data_stream
-
allow_custom_routing
-
(Optional, Boolean) If
true
, the data stream supports custom routing. Defaults tofalse
. -
hidden
-
(Optional, Boolean) If
true
, the data stream is hidden. Defaults tofalse
. -
index_mode
-
(Optional, string) Type of data stream to create. Valid values are
null
(regular data stream) andtime_series
(time series data stream).If
time_series
, each backing index has anindex.mode
index setting oftime_series
.
-
-
index_patterns
-
(Required, array of strings) Array of wildcard (
*
) expressions used to match the names of data streams and indices during creation.Elasticsearch includes several built-in index templates. To avoid naming collisions with these templates, see Avoid index pattern collisions.
-
_meta
- (Optional, object) Optional user metadata about the index template. May have any contents. This map is not automatically generated by Elasticsearch.
-
priority
- (Optional, integer) Priority to determine index template precedence when a new data stream or index is created. The index template with the highest priority is chosen. If no priority is specified the template is treated as though it is of priority 0 (lowest priority). This number is not automatically generated by Elasticsearch.
-
template
-
(Optional, object) Template to be applied. It may optionally include an
aliases
,mappings
, orsettings
configuration.Properties of
template
-
aliases
-
(Optional, object of objects) Aliases to add.
If the index template includes a
data_stream
object, these are data stream aliases. Otherwise, these are index aliases. Data stream aliases ignore theindex_routing
,routing
, andsearch_routing
options.Properties of
aliases
objects-
<alias>
-
(Required, object) The key is the alias name. Index alias names support date math.
The object body contains options for the alias. Supports an empty object.
Properties of
<alias>
-
filter
- (Optional, Query DSL object) Query used to limit documents the alias can access.
-
index_routing
-
(Optional, string) Value used to route indexing operations to a specific shard.
If specified, this overwrites the
routing
value for indexing operations. -
is_hidden
-
(Optional, Boolean) If
true
, the alias is hidden. Defaults tofalse
. All indices for the alias must have the sameis_hidden
value. -
is_write_index
-
(Optional, Boolean) If
true
, the index is the write index for the alias. Defaults tofalse
. -
routing
- (Optional, string) Value used to route indexing and search operations to a specific shard.
-
search_routing
-
(Optional, string) Value used to route search operations to a specific shard. If
specified, this overwrites the
routing
value for search operations.
-
-
-
mappings
-
(Optional, mapping object) Mapping for fields in the index. If specified, this mapping can include:
- Field names
- Field data types
- Mapping parameters
See Mapping.
-
settings
- (Optional, index setting object) Configuration options for the index. See Index Settings.
-
-
version
- (Optional, integer) Version number used to manage index templates externally. This number is not automatically generated by Elasticsearch.
Response body
edit-
overlapping
-
(array) Any templates that were superseded by the specified template.
Properties of
overlapping
-
index_patterns
- (array) Index patterns that the superseded template applies to.
-
name
- (string) Name of the superseded template.
-
-
template
-
(object) The settings, mappings, and aliases that would be applied to matching indices.
Properties of
template
-
aliases
-
(Optional, object of objects) Aliases for the index. If the index template includes
data_stream
, this parameter is not supported.Properties of
aliases
objects-
<alias>
-
(Required, object) The key is the alias name. Index alias names support date math.
The object body contains options for the alias. Supports an empty object.
Properties of
<alias>
-
filter
- (Optional, Query DSL object) Query used to limit documents the alias can access.
-
index_routing
-
(Optional, string) Value used to route indexing operations to a specific shard.
If specified, this overwrites the
routing
value for indexing operations. -
is_hidden
-
(Optional, Boolean) If
true
, the alias is hidden. Defaults tofalse
. All indices for the alias must have the sameis_hidden
value. -
is_write_index
-
(Optional, Boolean) If
true
, the index is the write index for the alias. Defaults tofalse
. -
routing
- (Optional, string) Value used to route indexing and search operations to a specific shard.
-
search_routing
-
(Optional, string) Value used to route search operations to a specific shard. If
specified, this overwrites the
routing
value for search operations.
-
-
-
mappings
-
(Optional, mapping object) Mapping for fields in the index. If specified, this mapping can include:
- Field names
- Field data types
- Mapping parameters
See Mapping.
-
settings
- (Optional, index setting object) Configuration options for the index. See Index Settings.
-
Examples
editSimulating an existing template
editThe following example creates and simulates a composed template:
response = client.cluster.put_component_template( name: 'ct1', body: { template: { settings: { 'index.number_of_shards' => 2 } } } ) puts response response = client.cluster.put_component_template( name: 'ct2', body: { template: { settings: { 'index.number_of_replicas' => 0 }, mappings: { properties: { "@timestamp": { type: 'date' } } } } } ) puts response response = client.indices.put_index_template( name: 'final-template', body: { index_patterns: [ 'my-index-*' ], composed_of: [ 'ct1', 'ct2' ], priority: 5 } ) puts response response = client.indices.simulate_template( name: 'final-template' ) puts response
PUT /_component_template/ct1 { "template": { "settings": { "index.number_of_shards": 2 } } } PUT /_component_template/ct2 { "template": { "settings": { "index.number_of_replicas": 0 }, "mappings": { "properties": { "@timestamp": { "type": "date" } } } } } PUT /_index_template/final-template { "index_patterns": ["my-index-*"], "composed_of": ["ct1", "ct2"], "priority": 5 } POST /_index_template/_simulate/final-template
Create a component template ( |
|
Create a component template ( |
|
Create an index template ( |
|
Show the configuration applied by the |
The response shows the index settings, mappings, and aliases applied by the final-template
:
{ "template" : { "settings" : { "index" : { "number_of_shards" : "2", "number_of_replicas" : "0", "routing" : { "allocation" : { "include" : { "_tier_preference" : "data_content" } } } } }, "mappings" : { "properties" : { "@timestamp" : { "type" : "date" } } }, "aliases" : { } }, "overlapping" : [ ] }
Simulating an arbitrary template configuration
editTo see what settings will be applied by a template before you add it to the cluster, you can pass a template configuration in the request body. The specified template is used for the simulation if it has a higher priority than existing templates.
response = client.indices.simulate_template( body: { index_patterns: [ 'my-index-*' ], composed_of: [ 'ct2' ], priority: 10, template: { settings: { 'index.number_of_replicas' => 1 } } } ) puts response
POST /_index_template/_simulate { "index_patterns": ["my-index-*"], "composed_of": ["ct2"], "priority": 10, "template": { "settings": { "index.number_of_replicas": 1 } } }
The response shows any overlapping templates with a lower priority.
{ "template" : { "settings" : { "index" : { "number_of_replicas" : "1", "routing" : { "allocation" : { "include" : { "_tier_preference" : "data_content" } } } } }, "mappings" : { "properties" : { "@timestamp" : { "type" : "date" } } }, "aliases" : { } }, "overlapping" : [ { "name" : "final-template", "index_patterns" : [ "my-index-*" ] } ] }