put-transform.asciidoc 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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. `pipeline`:::
  88. (Optional, string)
  89. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-pipeline]
  90. ====
  91. //End dest
  92. `frequency`::
  93. (Optional, <<time-units, time units>>)
  94. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=frequency]
  95. //Begin latest
  96. `latest`::
  97. (Required^*^, object)
  98. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-latest]
  99. +
  100. .Properties of `latest`
  101. [%collapsible%open]
  102. ====
  103. `sort`:::
  104. (Required, string)
  105. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-sort]
  106. `unique_key`:::
  107. (Required, array of strings)
  108. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-unique-key]
  109. ====
  110. //End latest
  111. //Begin _meta
  112. `_meta`::
  113. (Optional, object)
  114. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-metadata]
  115. //End _meta
  116. //Begin pivot
  117. `pivot`::
  118. (Required^*^, object)
  119. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot]
  120. +
  121. .Properties of `pivot`
  122. [%collapsible%open]
  123. ====
  124. `aggregations` or `aggs`:::
  125. (Required, object)
  126. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-aggs]
  127. `group_by`:::
  128. (Required, object)
  129. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-group-by]
  130. ====
  131. //End pivot
  132. //Begin retention policy
  133. `retention_policy`::
  134. (Optional, object)
  135. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention]
  136. +
  137. .Properties of `retention_policy`
  138. [%collapsible%open]
  139. ====
  140. `time`:::
  141. (Required, object)
  142. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time]
  143. +
  144. .Properties of `time`
  145. [%collapsible%open]
  146. =====
  147. `field`:::
  148. (Required, string)
  149. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time-field]
  150. `max_age`:::
  151. (Required, <<time-units, time units>>)
  152. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time-max-age]
  153. =====
  154. ====
  155. //End retention policy
  156. //Begin settings
  157. `settings`::
  158. (Optional, object)
  159. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings]
  160. +
  161. .Properties of `settings`
  162. [%collapsible%open]
  163. ====
  164. `dates_as_epoch_millis`:::
  165. (Optional, boolean)
  166. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-dates-as-epoch-milli]
  167. `docs_per_second`:::
  168. (Optional, float)
  169. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-docs-per-second]
  170. `align_checkpoints`:::
  171. (Optional, boolean)
  172. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-align-checkpoints]
  173. `deduce_mappings`:::
  174. (Optional, boolean)
  175. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-deduce-mappings]
  176. `max_page_search_size`:::
  177. (Optional, integer)
  178. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-max-page-search-size]
  179. `num_failure_retries`:::
  180. (Optional, integer)
  181. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-num-failure-retries]
  182. ====
  183. //End settings
  184. //Begin source
  185. `source`::
  186. (Required, object)
  187. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-transforms]
  188. +
  189. .Properties of `source`
  190. [%collapsible%open]
  191. ====
  192. `index`:::
  193. (Required, string or array)
  194. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-index-transforms]
  195. `query`:::
  196. (Optional, object)
  197. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-query-transforms]
  198. `runtime_mappings`:::
  199. (Optional, object)
  200. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-runtime-mappings-transforms]
  201. ====
  202. //End source
  203. //Begin sync
  204. `sync`::
  205. (Optional, object)
  206. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync]
  207. +
  208. .Properties of `sync`
  209. [%collapsible%open]
  210. ====
  211. //Begin time
  212. `time`:::
  213. (Required, object)
  214. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time]
  215. +
  216. .Properties of `time`
  217. [%collapsible%open]
  218. =====
  219. `delay`::::
  220. (Optional, <<time-units, time units>>)
  221. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-delay]
  222. `field`::::
  223. (Required, string)
  224. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-field]
  225. +
  226. --
  227. TIP: It is strongly recommended to use a field that contains the
  228. <<access-ingest-metadata,ingest timestamp>>. If you use a different field,
  229. you might need to set the `delay` such that it accounts for data transmission
  230. delays.
  231. --
  232. =====
  233. //End time
  234. ====
  235. //End sync
  236. [[put-transform-example]]
  237. == {api-examples-title}
  238. The following {transform} uses the `pivot` method:
  239. [source,console]
  240. --------------------------------------------------
  241. PUT _transform/ecommerce_transform1
  242. {
  243. "source": {
  244. "index": "kibana_sample_data_ecommerce",
  245. "query": {
  246. "term": {
  247. "geoip.continent_name": {
  248. "value": "Asia"
  249. }
  250. }
  251. }
  252. },
  253. "pivot": {
  254. "group_by": {
  255. "customer_id": {
  256. "terms": {
  257. "field": "customer_id"
  258. }
  259. }
  260. },
  261. "aggregations": {
  262. "max_price": {
  263. "max": {
  264. "field": "taxful_total_price"
  265. }
  266. }
  267. }
  268. },
  269. "description": "Maximum priced ecommerce data by customer_id in Asia",
  270. "dest": {
  271. "index": "kibana_sample_data_ecommerce_transform1",
  272. "pipeline": "add_timestamp_pipeline"
  273. },
  274. "frequency": "5m",
  275. "sync": {
  276. "time": {
  277. "field": "order_date",
  278. "delay": "60s"
  279. }
  280. },
  281. "retention_policy": {
  282. "time": {
  283. "field": "order_date",
  284. "max_age": "30d"
  285. }
  286. }
  287. }
  288. --------------------------------------------------
  289. // TEST[setup:kibana_sample_data_ecommerce,add_timestamp_pipeline]
  290. When the {transform} is created, you receive the following results:
  291. [source,console-result]
  292. ----
  293. {
  294. "acknowledged" : true
  295. }
  296. ----
  297. The following {transform} uses the `latest` method:
  298. [source,console]
  299. --------------------------------------------------
  300. PUT _transform/ecommerce_transform2
  301. {
  302. "source": {
  303. "index": "kibana_sample_data_ecommerce"
  304. },
  305. "latest": {
  306. "unique_key": ["customer_id"],
  307. "sort": "order_date"
  308. },
  309. "description": "Latest order for each customer",
  310. "dest": {
  311. "index": "kibana_sample_data_ecommerce_transform2"
  312. },
  313. "frequency": "5m",
  314. "sync": {
  315. "time": {
  316. "field": "order_date",
  317. "delay": "60s"
  318. }
  319. }
  320. }
  321. --------------------------------------------------
  322. // TEST[setup:kibana_sample_data_ecommerce]