put-transform.asciidoc 9.1 KB

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