index-templates.asciidoc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. If you use the {agent}, assign your index templates a priority
  30. lower than `100` to avoid overriding the built-in templates. Otherwise, to avoid
  31. accidentally applying the built-in templates, do one or more of the following:
  32. - To disable all built-index index and component templates, set
  33. <<stack-templates-enabled,`stack.templates.enabled`>> to `false` using the
  34. <<cluster-update-settings,cluster update settings API>>.
  35. - Use a non-overlapping index pattern.
  36. - Assign templates with an overlapping pattern a `priority` higher than `100`.
  37. For example, if you don't use the {agent} and want to create a template for the
  38. `logs-*` index pattern, assign your template a priority of `200`. This ensures
  39. your template is applied instead of the built-in template for `logs-*-*`.
  40. ====
  41. // end::built-in-index-templates[]
  42. When a composable template matches a given index
  43. it always takes precedence over a legacy template. If no composable template matches, a legacy
  44. template may still match and be applied.
  45. If an index is created with explicit settings and also matches an index template,
  46. the settings from the create index request take precedence over settings specified in the index template and its component templates.
  47. [source,console]
  48. --------------------------------------------------
  49. PUT _component_template/component_template1
  50. {
  51. "template": {
  52. "mappings": {
  53. "properties": {
  54. "@timestamp": {
  55. "type": "date"
  56. }
  57. }
  58. }
  59. }
  60. }
  61. PUT _component_template/other_component_template
  62. {
  63. "template": {
  64. "mappings": {
  65. "properties": {
  66. "ip_address": {
  67. "type": "ip"
  68. }
  69. }
  70. }
  71. }
  72. }
  73. PUT _index_template/template_1
  74. {
  75. "index_patterns": ["te*", "bar*"],
  76. "template": {
  77. "settings": {
  78. "number_of_shards": 1
  79. },
  80. "mappings": {
  81. "_source": {
  82. "enabled": false
  83. },
  84. "properties": {
  85. "host_name": {
  86. "type": "keyword"
  87. },
  88. "created_at": {
  89. "type": "date",
  90. "format": "EEE MMM dd HH:mm:ss Z yyyy"
  91. }
  92. }
  93. },
  94. "aliases": {
  95. "mydata": { }
  96. }
  97. },
  98. "priority": 200,
  99. "composed_of": ["component_template1", "other_component_template"],
  100. "version": 3,
  101. "_meta": {
  102. "description": "my custom"
  103. }
  104. }
  105. --------------------------------------------------
  106. // TESTSETUP
  107. ////
  108. [source,console]
  109. --------------------------------------------------
  110. DELETE _index_template/*
  111. DELETE _component_template/*
  112. --------------------------------------------------
  113. // TEARDOWN
  114. ////
  115. include::simulate-multi-component-templates.asciidoc[]