simulate-template.asciidoc 6.9 KB

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