Simulate index template API

Simulate index template API

New API reference

For the most up-to-date API details, refer to Index APIs.

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

  1. resp = client.indices.simulate_template(
  2. name="template_1",
  3. )
  4. print(resp)
  1. const response = await client.indices.simulateTemplate({
  2. name: "template_1",
  3. });
  4. console.log(response);
  1. POST /_index_template/_simulate/template_1

Request

POST /_index_template/_simulate/<index-template>

Prerequisites

  • If the Elasticsearch security features are enabled, you must have the manage_index_templates or manage cluster privilege to use this API.

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) Period to wait for the master node. If the master node is not available before the timeout expires, the request fails and returns an error. Defaults to 30s. Can also be set to -1 to indicate that the request should never timeout.

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 to false.

Request body

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 to false.

    hidden

    (Optional, Boolean) If true, the data stream is hidden. Defaults to false.

    index_mode

    (Optional, string) Type of data stream to create. Valid values are null (standard data stream), time_series (time series data stream) and logsdb (logs data stream).

    The template’s index_mode sets the index.mode of the backing index.

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, or settings 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 the index_routing, routing, and search_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 to false. All indices for the alias must have the same is_hidden value.

      is_write_index

      (Optional, Boolean) If true, the index is the write index for the alias. Defaults to false.

      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:

    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.

deprecated

(Optional, boolean) Marks this index template as deprecated. When creating or updating a non-deprecated index template that uses deprecated components, Elasticsearch will emit a deprecation warning.

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

  • 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 to false. All indices for the alias must have the same is_hidden value.

      is_write_index

      (Optional, Boolean) If true, the index is the write index for the alias. Defaults to false.

      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:

    See Mapping.

    settings

    (Optional, index setting object) Configuration options for the index. See Index settings.

Examples

Simulating an existing template

The following example creates and simulates a composed template:

  1. resp = client.cluster.put_component_template(
  2. name="ct1",
  3. template={
  4. "settings": {
  5. "index.number_of_shards": 2
  6. }
  7. },
  8. )
  9. print(resp)
  10. resp1 = client.cluster.put_component_template(
  11. name="ct2",
  12. template={
  13. "settings": {
  14. "index.number_of_replicas": 0
  15. },
  16. "mappings": {
  17. "properties": {
  18. "@timestamp": {
  19. "type": "date"
  20. }
  21. }
  22. }
  23. },
  24. )
  25. print(resp1)
  26. resp2 = client.indices.put_index_template(
  27. name="final-template",
  28. index_patterns=[
  29. "my-index-*"
  30. ],
  31. composed_of=[
  32. "ct1",
  33. "ct2"
  34. ],
  35. priority=5,
  36. )
  37. print(resp2)
  38. resp3 = client.indices.simulate_template(
  39. name="final-template",
  40. )
  41. print(resp3)
  1. response = client.cluster.put_component_template(
  2. name: 'ct1',
  3. body: {
  4. template: {
  5. settings: {
  6. 'index.number_of_shards' => 2
  7. }
  8. }
  9. }
  10. )
  11. puts response
  12. response = client.cluster.put_component_template(
  13. name: 'ct2',
  14. body: {
  15. template: {
  16. settings: {
  17. 'index.number_of_replicas' => 0
  18. },
  19. mappings: {
  20. properties: {
  21. "@timestamp": {
  22. type: 'date'
  23. }
  24. }
  25. }
  26. }
  27. }
  28. )
  29. puts response
  30. response = client.indices.put_index_template(
  31. name: 'final-template',
  32. body: {
  33. index_patterns: [
  34. 'my-index-*'
  35. ],
  36. composed_of: [
  37. 'ct1',
  38. 'ct2'
  39. ],
  40. priority: 5
  41. }
  42. )
  43. puts response
  44. response = client.indices.simulate_template(
  45. name: 'final-template'
  46. )
  47. puts response
  1. const response = await client.cluster.putComponentTemplate({
  2. name: "ct1",
  3. template: {
  4. settings: {
  5. "index.number_of_shards": 2,
  6. },
  7. },
  8. });
  9. console.log(response);
  10. const response1 = await client.cluster.putComponentTemplate({
  11. name: "ct2",
  12. template: {
  13. settings: {
  14. "index.number_of_replicas": 0,
  15. },
  16. mappings: {
  17. properties: {
  18. "@timestamp": {
  19. type: "date",
  20. },
  21. },
  22. },
  23. },
  24. });
  25. console.log(response1);
  26. const response2 = await client.indices.putIndexTemplate({
  27. name: "final-template",
  28. index_patterns: ["my-index-*"],
  29. composed_of: ["ct1", "ct2"],
  30. priority: 5,
  31. });
  32. console.log(response2);
  33. const response3 = await client.indices.simulateTemplate({
  34. name: "final-template",
  35. });
  36. console.log(response3);
  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. "routing" : {
  8. "allocation" : {
  9. "include" : {
  10. "_tier_preference" : "data_content"
  11. }
  12. }
  13. }
  14. }
  15. },
  16. "mappings" : {
  17. "properties" : {
  18. "@timestamp" : {
  19. "type" : "date"
  20. }
  21. }
  22. },
  23. "aliases" : { }
  24. },
  25. "overlapping" : [ ]
  26. }

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. resp = client.indices.simulate_template(
  2. index_patterns=[
  3. "my-index-*"
  4. ],
  5. composed_of=[
  6. "ct2"
  7. ],
  8. priority=10,
  9. template={
  10. "settings": {
  11. "index.number_of_replicas": 1
  12. }
  13. },
  14. )
  15. print(resp)
  1. response = client.indices.simulate_template(
  2. body: {
  3. index_patterns: [
  4. 'my-index-*'
  5. ],
  6. composed_of: [
  7. 'ct2'
  8. ],
  9. priority: 10,
  10. template: {
  11. settings: {
  12. 'index.number_of_replicas' => 1
  13. }
  14. }
  15. }
  16. )
  17. puts response
  1. const response = await client.indices.simulateTemplate({
  2. index_patterns: ["my-index-*"],
  3. composed_of: ["ct2"],
  4. priority: 10,
  5. template: {
  6. settings: {
  7. "index.number_of_replicas": 1,
  8. },
  9. },
  10. });
  11. console.log(response);
  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. "routing" : {
  7. "allocation" : {
  8. "include" : {
  9. "_tier_preference" : "data_content"
  10. }
  11. }
  12. }
  13. }
  14. },
  15. "mappings" : {
  16. "properties" : {
  17. "@timestamp" : {
  18. "type" : "date"
  19. }
  20. }
  21. },
  22. "aliases" : { }
  23. },
  24. "overlapping" : [
  25. {
  26. "name" : "final-template",
  27. "index_patterns" : [
  28. "my-index-*"
  29. ]
  30. }
  31. ]
  32. }