index-templates.asciidoc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. [[index-templates]]
  2. = Index templates
  3. NOTE: This topic describes the composable index templates introduced in {es} 7.8.
  4. For information about how index templates worked previously,
  5. see the <<indices-templates-v1,legacy template documentation>>.
  6. [[getting]]
  7. An index template is a way to tell {es} how to configure an index when it is created.
  8. For data streams, the index template configures the stream's backing indices as they
  9. are created. Templates are configured prior to index creation and then when an
  10. index is created either manually or through indexing a document, the template
  11. settings are used as a basis for creating the index.
  12. There are two types of templates, index templates and <<indices-component-template,component
  13. templates>>. Component templates are reusable building blocks that configure mappings, settings, and
  14. aliases. You use component templates to construct index templates, they aren't directly applied to a
  15. set of indices. Index templates can contain a collection of component templates, as well as directly
  16. specify settings, mappings, and aliases.
  17. If a new data stream or index matches more than one index template, the index template with the highest priority is used.
  18. // tag::built-in-index-templates[]
  19. [IMPORTANT]
  20. ====
  21. {es} has built-in index templates, each with a priority of `100`, for the
  22. following index patterns:
  23. // tag::built-in-index-template-patterns[]
  24. - `logs-*-*`
  25. - `metrics-*-*`
  26. - `synthetics-*-*`
  27. // end::built-in-index-template-patterns[]
  28. The {fleet-guide}/fleet-overview.html[{agent}] uses these templates to create
  29. data streams. Index templates created by {fleet} integrations use similar
  30. overlapping index patterns and have a priority up to `200`.
  31. If you use {fleet} or the {agent}, assign your index templates a priority
  32. lower than `100` to avoid overriding these templates. Otherwise, to avoid
  33. accidentally applying the templates, do one or more of the following:
  34. - To disable all built-in index and component templates, set
  35. <<stack-templates-enabled,`stack.templates.enabled`>> to `false` using the
  36. <<cluster-update-settings,cluster update settings API>>.
  37. - Use a non-overlapping index pattern.
  38. - Assign templates with an overlapping pattern a `priority` higher than `200`.
  39. For example, if you don't use {fleet} or the {agent} and want to create a
  40. template for the `logs-*` index pattern, assign your template a priority of
  41. `500`. This ensures your template is applied instead of the built-in template
  42. for `logs-*-*`.
  43. ====
  44. // end::built-in-index-templates[]
  45. When a composable template matches a given index
  46. it always takes precedence over a legacy template. If no composable template matches, a legacy
  47. template may still match and be applied.
  48. If an index is created with explicit settings and also matches an index template,
  49. the settings from the create index request take precedence over settings specified in the index template and its component templates.
  50. [source,console]
  51. --------------------------------------------------
  52. PUT _component_template/component_template1
  53. {
  54. "template": {
  55. "mappings": {
  56. "properties": {
  57. "@timestamp": {
  58. "type": "date"
  59. }
  60. }
  61. }
  62. }
  63. }
  64. PUT _component_template/other_component_template
  65. {
  66. "template": {
  67. "mappings": {
  68. "properties": {
  69. "ip_address": {
  70. "type": "ip"
  71. }
  72. }
  73. }
  74. }
  75. }
  76. PUT _index_template/template_1
  77. {
  78. "index_patterns": ["te*", "bar*"],
  79. "template": {
  80. "settings": {
  81. "number_of_shards": 1
  82. },
  83. "mappings": {
  84. "_source": {
  85. "enabled": false
  86. },
  87. "properties": {
  88. "host_name": {
  89. "type": "keyword"
  90. },
  91. "created_at": {
  92. "type": "date",
  93. "format": "EEE MMM dd HH:mm:ss Z yyyy"
  94. }
  95. }
  96. },
  97. "aliases": {
  98. "mydata": { }
  99. }
  100. },
  101. "priority": 500,
  102. "composed_of": ["component_template1", "other_component_template"],
  103. "version": 3,
  104. "_meta": {
  105. "description": "my custom"
  106. }
  107. }
  108. --------------------------------------------------
  109. // TESTSETUP
  110. ////
  111. [source,console]
  112. --------------------------------------------------
  113. DELETE _index_template/*
  114. DELETE _component_template/*
  115. --------------------------------------------------
  116. // TEARDOWN
  117. ////
  118. include::simulate-multi-component-templates.asciidoc[]