put-transform.asciidoc 9.7 KB

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