simulate-template.asciidoc 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. [[indices-simulate-template]]
  2. === Simulate index template API
  3. ++++
  4. <titleabbrev>Simulate template</titleabbrev>
  5. ++++
  6. Returns the index configuration that would be applied by a particular
  7. <<index-templates, index template>>.
  8. ////
  9. [source,console]
  10. --------------------------------------------------
  11. PUT _index_template/template_1
  12. {
  13. "index_patterns": ["te*", "bar*"],
  14. "template": {
  15. "settings": {
  16. "number_of_shards": 1
  17. },
  18. "mappings": {
  19. "_source": {
  20. "enabled": false
  21. },
  22. "properties": {
  23. "host_name": {
  24. "type": "keyword"
  25. },
  26. "created_at": {
  27. "type": "date",
  28. "format": "EEE MMM dd HH:mm:ss Z yyyy"
  29. }
  30. }
  31. },
  32. "aliases": {
  33. "mydata": { }
  34. }
  35. },
  36. "priority": 10,
  37. "version": 3,
  38. "_meta": {
  39. "description": "my custom"
  40. }
  41. }
  42. --------------------------------------------------
  43. // TESTSETUP
  44. [source,console]
  45. --------------------------------------------------
  46. DELETE _index_template/*
  47. --------------------------------------------------
  48. // TEARDOWN
  49. ////
  50. [source,console]
  51. --------------------------------------------------
  52. POST /_index_template/_simulate/template_1
  53. --------------------------------------------------
  54. [[simulate-template-api-request]]
  55. ==== {api-request-title}
  56. `POST /_index_template/_simulate/<index-template>`
  57. [[simulate-template-api-prereqs]]
  58. ==== {api-prereq-title}
  59. * If the {es} {security-features} are enabled, you must have the
  60. `manage_index_templates` or `manage` <<privileges-list-cluster,cluster
  61. privilege>> to use this API.
  62. [[simulate-template-api-path-params]]
  63. ==== {api-path-parms-title}
  64. `<index-template>`::
  65. (Optional, string)
  66. Name of the index template to simulate.
  67. To test a template configuration before you add it to the cluster,
  68. omit this parameter and specify the template configuration in the request body.
  69. [[simulate-template-api-query-params]]
  70. ==== {api-query-parms-title}
  71. ////
  72. `cause`::
  73. (Optional, string) The reason for using the specified template for the simulation.
  74. ////
  75. `create`::
  76. (Optional, Boolean) If `true`, the template passed in the body is
  77. only used if no existing templates match the same index patterns.
  78. If `false`, the simulation uses the template with the highest priority.
  79. Note that the template is not permanently added or updated in either case;
  80. it is only used for the simulation.
  81. Defaults to `false`.
  82. include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=master-timeout]
  83. [role="child_attributes"]
  84. [[simulate-template-api-request-body]]
  85. ==== {api-request-body-title}
  86. include::{es-ref-dir}/indices/put-index-template.asciidoc[tag=index-template-api-body]
  87. [role="child_attributes"]
  88. [[simulate-template-api-response-body]]
  89. ==== {api-response-body-title}
  90. `overlapping`::
  91. (array) Any templates that were superseded by the specified template.
  92. +
  93. .Properties of `overlapping`
  94. [%collapsible%open]
  95. ====
  96. `index_patterns`::
  97. (array) Index patterns that the superseded template applies to.
  98. `name`::
  99. (string) Name of the superseded template.
  100. ====
  101. `template`::
  102. (object)
  103. The settings, mappings, and aliases that would be applied to matching indices.
  104. +
  105. .Properties of `template`
  106. [%collapsible%open]
  107. ====
  108. `aliases`::
  109. (Optional, object of objects) Aliases for the index. If the index template
  110. includes `data_stream`, this parameter is not supported.
  111. +
  112. include::{es-repo-dir}/indices/create-index.asciidoc[tag=aliases-props]
  113. include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=mappings]
  114. include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=settings]
  115. ====
  116. [[simulate-template-api-example]]
  117. ==== {api-examples-title}
  118. [[simulate-existing-template-ex]]
  119. ===== Simulating an existing template
  120. The following example creates and simulates a composed template:
  121. [source,console]
  122. --------------------------------------------------
  123. PUT /_component_template/ct1 <1>
  124. {
  125. "template": {
  126. "settings": {
  127. "index.number_of_shards": 2
  128. }
  129. }
  130. }
  131. PUT /_component_template/ct2 <2>
  132. {
  133. "template": {
  134. "settings": {
  135. "index.number_of_replicas": 0
  136. },
  137. "mappings": {
  138. "properties": {
  139. "@timestamp": {
  140. "type": "date"
  141. }
  142. }
  143. }
  144. }
  145. }
  146. PUT /_index_template/final-template <3>
  147. {
  148. "index_patterns": ["my-index-*"],
  149. "composed_of": ["ct1", "ct2"],
  150. "priority": 5
  151. }
  152. POST /_index_template/_simulate/final-template <4>
  153. --------------------------------------------------
  154. <1> Create a component template (`ct1`) that sets the number of shards to 2
  155. <2> Create a component template (`ct2`) that sets the number of replicas to 0 and defines a mapping
  156. <3> Create an index template (`final-template`) that uses the component templates
  157. <4> Show the configuration applied by the `final-template`
  158. The response shows the index settings, mappings, and aliases applied by the `final-template`:
  159. [source,console-result]
  160. ---------------------------------------------------------
  161. {
  162. "template" : {
  163. "settings" : {
  164. "index" : {
  165. "number_of_shards" : "2", <1>
  166. "number_of_replicas" : "0", <2>
  167. "routing" : {
  168. "allocation" : {
  169. "include" : {
  170. "_tier_preference" : "data_content"
  171. }
  172. }
  173. }
  174. }
  175. },
  176. "mappings" : { <3>
  177. "properties" : {
  178. "@timestamp" : {
  179. "type" : "date"
  180. }
  181. }
  182. },
  183. "aliases" : { }
  184. },
  185. "overlapping" : [ ]
  186. }
  187. ---------------------------------------------------------
  188. <1> Number of shards from `ct1`
  189. <2> Number of replicas from `ct2`
  190. <3> Mappings from `ct1`
  191. [[simulate-template-config-ex]]
  192. ===== Simulating an arbitrary template configuration
  193. To see what settings will be applied by a template before you add it to the cluster,
  194. you can pass a template configuration in the request body.
  195. The specified template is used for the simulation if it has a higher priority than existing templates.
  196. [source,console]
  197. --------------------------------------------------
  198. POST /_index_template/_simulate
  199. {
  200. "index_patterns": ["my-index-*"],
  201. "composed_of": ["ct2"],
  202. "priority": 10,
  203. "template": {
  204. "settings": {
  205. "index.number_of_replicas": 1
  206. }
  207. }
  208. }
  209. --------------------------------------------------
  210. // TEST[continued]
  211. The response shows any overlapping templates with a lower priority.
  212. [source,console-result]
  213. ---------------------------------------------------------
  214. {
  215. "template" : {
  216. "settings" : {
  217. "index" : {
  218. "number_of_replicas" : "1",
  219. "routing" : {
  220. "allocation" : {
  221. "include" : {
  222. "_tier_preference" : "data_content"
  223. }
  224. }
  225. }
  226. }
  227. },
  228. "mappings" : {
  229. "properties" : {
  230. "@timestamp" : {
  231. "type" : "date"
  232. }
  233. }
  234. },
  235. "aliases" : { }
  236. },
  237. "overlapping" : [
  238. {
  239. "name" : "final-template",
  240. "index_patterns" : [
  241. "my-index-*"
  242. ]
  243. }
  244. ]
  245. }
  246. ---------------------------------------------------------