Simulate index template API

This functionality is experimental and may be changed or removed completely in a future release. Elastic will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features.

Returns the index configuration that would be applied by a particular index template.

  1. POST /_index_template/_simulate/template_1

Request

POST /_index_template/_simulate/<index-template>

Path parameters

<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

create

(Optional, boolean) If true, the template passed in the body is only used if no existing templates match the same index patterns. If false, 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 to false.

master_timeout

(Optional, time units) Specifies the period of time 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.

Request body

composed_of

(Optional, array of strings) Ordered list of component template names. Component templates are merged in the order specified, meaning that the last component template specified has the highest precedence. For an example, see Composing multiple component templates.

index_patterns

(Required, array of strings) Array of wildcard (*) expressions used to match the names of indices during creation.

priority

(Optional, integer) Priority that determines what template is applied if there are multiple templates that match the name of a new index. The highest priority template takes precedence. Defaults to 0 (lowest priority).

template

(Optional, object) Template to apply.

Properties of template

version

(Optional, integer) Version number used to manage index templates externally. This version is not automatically generated by Elasticsearch.

_meta

(Optional, object) User-specified metadata for the index template. This information is not generated or used by Elasticsearch.

Response body

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

Examples

Simulating an existing template

The following example creates and simulates a composed template:

  1. PUT /_component_template/ct1
  2. {
  3. "template": {
  4. "settings": {
  5. "index.number_of_shards": 2
  6. }
  7. }
  8. }
  9. PUT /_component_template/ct2
  10. {
  11. "template": {
  12. "settings": {
  13. "index.number_of_replicas": 0
  14. },
  15. "mappings": {
  16. "properties": {
  17. "@timestamp": {
  18. "type": "date"
  19. }
  20. }
  21. }
  22. }
  23. }
  24. PUT /_index_template/final-template
  25. {
  26. "index_patterns": ["my-index-*"],
  27. "composed_of": ["ct1", "ct2"],
  28. "priority": 5
  29. }
  30. POST /_index_template/_simulate/final-template

Create a component template (ct1) that sets the number of shards to 2

Create a component template (ct2) that sets the number of replicas to 0 and defines a mapping

Create an index template (final-template) that uses the component templates

Show the configuration applied by the final-template

The response shows the index settings, mappings, and aliases applied by the final-template:

  1. {
  2. "template" : {
  3. "settings" : {
  4. "index" : {
  5. "number_of_shards" : "2",
  6. "number_of_replicas" : "0"
  7. }
  8. },
  9. "mappings" : {
  10. "properties" : {
  11. "@timestamp" : {
  12. "type" : "date"
  13. }
  14. }
  15. },
  16. "aliases" : { }
  17. },
  18. "overlapping" : [ ]
  19. }

Number of shards from ct1

Number of replicas from ct2

Mappings from ct1

Simulating an arbitrary template configuration

To 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.

  1. POST /_index_template/_simulate
  2. {
  3. "index_patterns": ["my-index-*"],
  4. "composed_of": ["ct2"],
  5. "priority": 10,
  6. "template": {
  7. "settings": {
  8. "index.number_of_replicas": 1
  9. }
  10. }
  11. }

The response shows any overlapping templates with a lower priority.

  1. {
  2. "template" : {
  3. "settings" : {
  4. "index" : {
  5. "number_of_replicas" : "1"
  6. }
  7. },
  8. "mappings" : {
  9. "properties" : {
  10. "@timestamp" : {
  11. "type" : "date"
  12. }
  13. }
  14. },
  15. "aliases" : { }
  16. },
  17. "overlapping" : [
  18. {
  19. "name" : "final-template",
  20. "index_patterns" : [
  21. "my-index-*"
  22. ]
  23. }
  24. ]
  25. }