simulate-template.asciidoc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. `include_defaults`::
  84. (Optional, Boolean) Functionality in preview:[]. If `true`, return all default settings in the response.
  85. Defaults to `false`.
  86. [role="child_attributes"]
  87. [[simulate-template-api-request-body]]
  88. ==== {api-request-body-title}
  89. include::{es-ref-dir}/indices/put-index-template.asciidoc[tag=index-template-api-body]
  90. [role="child_attributes"]
  91. [[simulate-template-api-response-body]]
  92. ==== {api-response-body-title}
  93. `overlapping`::
  94. (array) Any templates that were superseded by the specified template.
  95. +
  96. .Properties of `overlapping`
  97. [%collapsible%open]
  98. ====
  99. `index_patterns`::
  100. (array) Index patterns that the superseded template applies to.
  101. `name`::
  102. (string) Name of the superseded template.
  103. ====
  104. `template`::
  105. (object)
  106. The settings, mappings, and aliases that would be applied to matching indices.
  107. +
  108. .Properties of `template`
  109. [%collapsible%open]
  110. ====
  111. `aliases`::
  112. (Optional, object of objects) Aliases for the index. If the index template
  113. includes `data_stream`, this parameter is not supported.
  114. +
  115. include::{es-repo-dir}/indices/create-index.asciidoc[tag=aliases-props]
  116. include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=mappings]
  117. include::{es-ref-dir}/rest-api/common-parms.asciidoc[tag=settings]
  118. ====
  119. [[simulate-template-api-example]]
  120. ==== {api-examples-title}
  121. [[simulate-existing-template-ex]]
  122. ===== Simulating an existing template
  123. The following example creates and simulates a composed template:
  124. [source,console]
  125. --------------------------------------------------
  126. PUT /_component_template/ct1 <1>
  127. {
  128. "template": {
  129. "settings": {
  130. "index.number_of_shards": 2
  131. }
  132. }
  133. }
  134. PUT /_component_template/ct2 <2>
  135. {
  136. "template": {
  137. "settings": {
  138. "index.number_of_replicas": 0
  139. },
  140. "mappings": {
  141. "properties": {
  142. "@timestamp": {
  143. "type": "date"
  144. }
  145. }
  146. }
  147. }
  148. }
  149. PUT /_index_template/final-template <3>
  150. {
  151. "index_patterns": ["my-index-*"],
  152. "composed_of": ["ct1", "ct2"],
  153. "priority": 5
  154. }
  155. POST /_index_template/_simulate/final-template <4>
  156. --------------------------------------------------
  157. <1> Create a component template (`ct1`) that sets the number of shards to 2
  158. <2> Create a component template (`ct2`) that sets the number of replicas to 0 and defines a mapping
  159. <3> Create an index template (`final-template`) that uses the component templates
  160. <4> Show the configuration applied by the `final-template`
  161. The response shows the index settings, mappings, and aliases applied by the `final-template`:
  162. [source,console-result]
  163. ---------------------------------------------------------
  164. {
  165. "template" : {
  166. "settings" : {
  167. "index" : {
  168. "number_of_shards" : "2", <1>
  169. "number_of_replicas" : "0", <2>
  170. "routing" : {
  171. "allocation" : {
  172. "include" : {
  173. "_tier_preference" : "data_content"
  174. }
  175. }
  176. }
  177. }
  178. },
  179. "mappings" : { <3>
  180. "properties" : {
  181. "@timestamp" : {
  182. "type" : "date"
  183. }
  184. }
  185. },
  186. "aliases" : { }
  187. },
  188. "overlapping" : [ ]
  189. }
  190. ---------------------------------------------------------
  191. <1> Number of shards from `ct1`
  192. <2> Number of replicas from `ct2`
  193. <3> Mappings from `ct1`
  194. [[simulate-template-config-ex]]
  195. ===== Simulating an arbitrary template configuration
  196. To see what settings will be applied by a template before you add it to the cluster,
  197. you can pass a template configuration in the request body.
  198. The specified template is used for the simulation if it has a higher priority than existing templates.
  199. [source,console]
  200. --------------------------------------------------
  201. POST /_index_template/_simulate
  202. {
  203. "index_patterns": ["my-index-*"],
  204. "composed_of": ["ct2"],
  205. "priority": 10,
  206. "template": {
  207. "settings": {
  208. "index.number_of_replicas": 1
  209. }
  210. }
  211. }
  212. --------------------------------------------------
  213. // TEST[continued]
  214. The response shows any overlapping templates with a lower priority.
  215. [source,console-result]
  216. ---------------------------------------------------------
  217. {
  218. "template" : {
  219. "settings" : {
  220. "index" : {
  221. "number_of_replicas" : "1",
  222. "routing" : {
  223. "allocation" : {
  224. "include" : {
  225. "_tier_preference" : "data_content"
  226. }
  227. }
  228. }
  229. }
  230. },
  231. "mappings" : {
  232. "properties" : {
  233. "@timestamp" : {
  234. "type" : "date"
  235. }
  236. }
  237. },
  238. "aliases" : { }
  239. },
  240. "overlapping" : [
  241. {
  242. "name" : "final-template",
  243. "index_patterns" : [
  244. "my-index-*"
  245. ]
  246. }
  247. ]
  248. }
  249. ---------------------------------------------------------