put-transform.asciidoc 9.0 KB

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