put-transform.asciidoc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. [role="xpack"]
  2. [[put-transform]]
  3. = Create {transform} API
  4. [subs="attributes"]
  5. ++++
  6. <titleabbrev>Create {transform}</titleabbrev>
  7. ++++
  8. Instantiates a {transform}.
  9. [[put-transform-request]]
  10. == {api-request-title}
  11. `PUT _transform/<transform_id>`
  12. [[put-transform-prereqs]]
  13. == {api-prereq-title}
  14. Requires the following privileges:
  15. * cluster: `manage_transform` (the `transform_admin` built-in role grants this
  16. privilege)
  17. * source indices: `read`, `view_index_metadata`
  18. * destination index: `read`, `create_index`, `index`. If a `retention_policy` is configured, the `delete` privilege is
  19. also required.
  20. [[put-transform-desc]]
  21. == {api-description-title}
  22. This API defines a {transform}, which copies data from source indices,
  23. transforms it, and persists it into an entity-centric destination index. If you
  24. choose to use the pivot method for your {transform}, the entities are defined by
  25. the set of `group_by` fields in the `pivot` object. If you choose to use the
  26. latest method, the entities are defined by the `unique_key` field values in the
  27. `latest` object.
  28. You can also think of the destination index as a two-dimensional tabular data
  29. structure (known as a {dataframe}). The ID for each document in the {dataframe}
  30. is generated from a hash of the entity, so there is a unique row per entity. For
  31. more information, see <<transforms>>.
  32. When the {transform} is created, a series of validations occur to ensure its
  33. success. For example, there is a check for the existence of the source indices
  34. and a check that the destination index is not part of the source index pattern.
  35. You can use the `defer_validation` parameter to skip these checks.
  36. Deferred validations are always run when the {transform} is started, with the
  37. exception of privilege checks.
  38. [IMPORTANT]
  39. ====
  40. * The {transform} remembers which roles the user that created it had at the time
  41. of creation and uses those same roles. If those roles do not have the required
  42. privileges on the source and destination indices, the {transform} fails when it
  43. attempts unauthorized operations. If you provide
  44. <<http-clients-secondary-authorization,secondary authorization headers>>, those
  45. credentials are used instead.
  46. * You must use {kib} or this API to create a {transform}. Do not add a
  47. {transform} directly into any `.transform-internal*` indices using the {es}
  48. index API. If {es} {security-features} are enabled, do not give users any
  49. privileges on `.transform-internal*` indices. If you used {transforms} prior to
  50. 7.5, also do not give users any privileges on `.data-frame-internal*` indices.
  51. ====
  52. You must choose either the latest or pivot method for your {transform}; you
  53. cannot use both in a single {transform}.
  54. [[put-transform-path-parms]]
  55. == {api-path-parms-title}
  56. `<transform_id>`::
  57. (Required, string)
  58. Identifier for the {transform}. This identifier can contain lowercase
  59. alphanumeric characters (a-z and 0-9), hyphens, and underscores. It has a 64
  60. character limit and must start and end with alphanumeric characters.
  61. [[put-transform-query-parms]]
  62. == {api-query-parms-title}
  63. `defer_validation`::
  64. (Optional, Boolean) When `true`, deferrable validations are not run. This
  65. behavior may be desired if the source index does not exist until after the
  66. {transform} is created.
  67. `timeout`::
  68. (Optional, time)
  69. Period to wait for a response. If no response is received before the timeout
  70. expires, the request fails and returns an error. Defaults to `30s`.
  71. [role="child_attributes"]
  72. [[put-transform-request-body]]
  73. == {api-request-body-title}
  74. `description`::
  75. (Optional, string) Free text description of the {transform}.
  76. //Begin dest
  77. `dest`::
  78. (Required, object)
  79. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest]
  80. +
  81. .Properties of `dest`
  82. [%collapsible%open]
  83. ====
  84. `index`:::
  85. (Required, string)
  86. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-index]
  87. //Begin aliases
  88. `aliases`:::
  89. (Optional, array of objects)
  90. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-aliases]
  91. +
  92. .Properties of `aliases`
  93. [%collapsible%open]
  94. =====
  95. `alias`::::
  96. (Required, string)
  97. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-aliases-alias]
  98. `move_on_creation`::::
  99. (Optional, boolean)
  100. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-aliases-move-on-creation]
  101. =====
  102. //End aliases
  103. `pipeline`:::
  104. (Optional, string)
  105. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-pipeline]
  106. ====
  107. //End dest
  108. `frequency`::
  109. (Optional, <<time-units, time units>>)
  110. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=frequency]
  111. //Begin latest
  112. `latest`::
  113. (Required^*^, object)
  114. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-latest]
  115. +
  116. .Properties of `latest`
  117. [%collapsible%open]
  118. ====
  119. `sort`:::
  120. (Required, string)
  121. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-sort]
  122. `unique_key`:::
  123. (Required, array of strings)
  124. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-unique-key]
  125. ====
  126. //End latest
  127. //Begin _meta
  128. `_meta`::
  129. (Optional, object)
  130. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-metadata]
  131. //End _meta
  132. //Begin pivot
  133. `pivot`::
  134. (Required^*^, object)
  135. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot]
  136. +
  137. .Properties of `pivot`
  138. [%collapsible%open]
  139. ====
  140. `aggregations` or `aggs`:::
  141. (Required, object)
  142. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-aggs]
  143. `group_by`:::
  144. (Required, object)
  145. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-group-by]
  146. ====
  147. //End pivot
  148. //Begin retention policy
  149. `retention_policy`::
  150. (Optional, object)
  151. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention]
  152. +
  153. .Properties of `retention_policy`
  154. [%collapsible%open]
  155. ====
  156. `time`:::
  157. (Required, object)
  158. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time]
  159. +
  160. .Properties of `time`
  161. [%collapsible%open]
  162. =====
  163. `field`:::
  164. (Required, string)
  165. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time-field]
  166. `max_age`:::
  167. (Required, <<time-units, time units>>)
  168. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time-max-age]
  169. =====
  170. ====
  171. //End retention policy
  172. //Begin settings
  173. `settings`::
  174. (Optional, object)
  175. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings]
  176. +
  177. .Properties of `settings`
  178. [%collapsible%open]
  179. ====
  180. `align_checkpoints`:::
  181. (Optional, boolean)
  182. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-align-checkpoints]
  183. `dates_as_epoch_millis`:::
  184. (Optional, boolean)
  185. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-dates-as-epoch-milli]
  186. `deduce_mappings`:::
  187. (Optional, boolean)
  188. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-deduce-mappings]
  189. `docs_per_second`:::
  190. (Optional, float)
  191. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-docs-per-second]
  192. `max_page_search_size`:::
  193. (Optional, integer)
  194. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-max-page-search-size]
  195. `num_failure_retries`:::
  196. (Optional, integer)
  197. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-num-failure-retries]
  198. `unattended`:::
  199. (Optional, boolean)
  200. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-unattended]
  201. ====
  202. //End settings
  203. //Begin source
  204. `source`::
  205. (Required, object)
  206. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-transforms]
  207. +
  208. .Properties of `source`
  209. [%collapsible%open]
  210. ====
  211. `index`:::
  212. (Required, string or array)
  213. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-index-transforms]
  214. `query`:::
  215. (Optional, object)
  216. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-query-transforms]
  217. `runtime_mappings`:::
  218. (Optional, object)
  219. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-runtime-mappings-transforms]
  220. ====
  221. //End source
  222. //Begin sync
  223. `sync`::
  224. (Optional, object)
  225. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync]
  226. +
  227. .Properties of `sync`
  228. [%collapsible%open]
  229. ====
  230. //Begin time
  231. `time`:::
  232. (Required, object)
  233. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time]
  234. +
  235. .Properties of `time`
  236. [%collapsible%open]
  237. =====
  238. `delay`::::
  239. (Optional, <<time-units, time units>>)
  240. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-delay]
  241. `field`::::
  242. (Required, string)
  243. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-field]
  244. +
  245. --
  246. TIP: It is strongly recommended to use a field that contains the
  247. <<access-ingest-metadata,ingest timestamp>>. If you use a different field,
  248. you might need to set the `delay` such that it accounts for data transmission
  249. delays.
  250. --
  251. =====
  252. //End time
  253. ====
  254. //End sync
  255. [[put-transform-example]]
  256. == {api-examples-title}
  257. The following {transform} uses the `pivot` method:
  258. [source,console]
  259. --------------------------------------------------
  260. PUT _transform/ecommerce_transform1
  261. {
  262. "source": {
  263. "index": "kibana_sample_data_ecommerce",
  264. "query": {
  265. "term": {
  266. "geoip.continent_name": {
  267. "value": "Asia"
  268. }
  269. }
  270. }
  271. },
  272. "pivot": {
  273. "group_by": {
  274. "customer_id": {
  275. "terms": {
  276. "field": "customer_id",
  277. "missing_bucket": true
  278. }
  279. }
  280. },
  281. "aggregations": {
  282. "max_price": {
  283. "max": {
  284. "field": "taxful_total_price"
  285. }
  286. }
  287. }
  288. },
  289. "description": "Maximum priced ecommerce data by customer_id in Asia",
  290. "dest": {
  291. "index": "kibana_sample_data_ecommerce_transform1",
  292. "pipeline": "add_timestamp_pipeline"
  293. },
  294. "frequency": "5m",
  295. "sync": {
  296. "time": {
  297. "field": "order_date",
  298. "delay": "60s"
  299. }
  300. },
  301. "retention_policy": {
  302. "time": {
  303. "field": "order_date",
  304. "max_age": "30d"
  305. }
  306. }
  307. }
  308. --------------------------------------------------
  309. // TEST[setup:kibana_sample_data_ecommerce,add_timestamp_pipeline]
  310. When the {transform} is created, you receive the following results:
  311. [source,console-result]
  312. ----
  313. {
  314. "acknowledged" : true
  315. }
  316. ----
  317. The following {transform} uses the `latest` method:
  318. [source,console]
  319. --------------------------------------------------
  320. PUT _transform/ecommerce_transform2
  321. {
  322. "source": {
  323. "index": "kibana_sample_data_ecommerce"
  324. },
  325. "latest": {
  326. "unique_key": ["customer_id"],
  327. "sort": "order_date"
  328. },
  329. "description": "Latest order for each customer",
  330. "dest": {
  331. "index": "kibana_sample_data_ecommerce_transform2"
  332. },
  333. "frequency": "5m",
  334. "sync": {
  335. "time": {
  336. "field": "order_date",
  337. "delay": "60s"
  338. }
  339. }
  340. }
  341. --------------------------------------------------
  342. // TEST[setup:kibana_sample_data_ecommerce]