1
0

put-transform.asciidoc 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. Identifier for the {transform}. This identifier can contain lowercase
  53. alphanumeric characters (a-z and 0-9), hyphens, and underscores. It has a 64
  54. character limit and must start and end with alphanumeric characters.
  55. [[put-transform-query-parms]]
  56. == {api-query-parms-title}
  57. `defer_validation`::
  58. (Optional, Boolean) When `true`, deferrable validations are not run. This
  59. behavior may be desired if the source index does not exist until after the
  60. {transform} is created.
  61. `timeout`::
  62. (Optional, time)
  63. Period to wait for a response. If no response is received before the timeout
  64. expires, the request fails and returns an error. Defaults to `30s`.
  65. [role="child_attributes"]
  66. [[put-transform-request-body]]
  67. == {api-request-body-title}
  68. `description`::
  69. (Optional, string) Free text description of the {transform}.
  70. //Begin dest
  71. `dest`::
  72. (Required, object)
  73. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest]
  74. +
  75. .Properties of `dest`
  76. [%collapsible%open]
  77. ====
  78. `index`:::
  79. (Required, string)
  80. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-index]
  81. `pipeline`:::
  82. (Optional, string)
  83. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-pipeline]
  84. ====
  85. //End dest
  86. `frequency`::
  87. (Optional, <<time-units, time units>>)
  88. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=frequency]
  89. //Begin latest
  90. `latest`::
  91. (Required^*^, object)
  92. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-latest]
  93. +
  94. .Properties of `latest`
  95. [%collapsible%open]
  96. ====
  97. `sort`:::
  98. (Required, string)
  99. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-sort]
  100. `unique_key`:::
  101. (Required, array of strings)
  102. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-unique-key]
  103. ====
  104. //End latest
  105. //Begin _meta
  106. `_meta`::
  107. (Optional, object)
  108. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-metadata]
  109. //End _meta
  110. //Begin pivot
  111. `pivot`::
  112. (Required^*^, object)
  113. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot]
  114. +
  115. .Properties of `pivot`
  116. [%collapsible%open]
  117. ====
  118. `aggregations` or `aggs`:::
  119. (Required, object)
  120. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-aggs]
  121. `group_by`:::
  122. (Required, object)
  123. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-group-by]
  124. ====
  125. //End pivot
  126. //Begin retention policy
  127. `retention_policy`::
  128. (Optional, object)
  129. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention]
  130. +
  131. .Properties of `retention_policy`
  132. [%collapsible%open]
  133. ====
  134. `time`:::
  135. (Required, object)
  136. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time]
  137. +
  138. .Properties of `time`
  139. [%collapsible%open]
  140. =====
  141. `field`:::
  142. (Required, string)
  143. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time-field]
  144. `max_age`:::
  145. (Required, <<time-units, time units>>)
  146. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time-max-age]
  147. =====
  148. ====
  149. //End retention policy
  150. //Begin settings
  151. `settings`::
  152. (Optional, object)
  153. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings]
  154. +
  155. .Properties of `settings`
  156. [%collapsible%open]
  157. ====
  158. `dates_as_epoch_millis`:::
  159. (Optional, boolean)
  160. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-dates-as-epoch-milli]
  161. `docs_per_second`:::
  162. (Optional, float)
  163. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-docs-per-second]
  164. `align_checkpoints`:::
  165. (Optional, boolean)
  166. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-align-checkpoints]
  167. `max_page_search_size`:::
  168. (Optional, integer)
  169. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-max-page-search-size]
  170. ====
  171. //End settings
  172. //Begin source
  173. `source`::
  174. (Required, object)
  175. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-transforms]
  176. +
  177. .Properties of `source`
  178. [%collapsible%open]
  179. ====
  180. `index`:::
  181. (Required, string or array)
  182. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-index-transforms]
  183. `query`:::
  184. (Optional, object)
  185. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-query-transforms]
  186. `runtime_mappings`:::
  187. (Optional, object)
  188. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-runtime-mappings-transforms]
  189. ====
  190. //End source
  191. //Begin sync
  192. `sync`::
  193. (Optional, object)
  194. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync]
  195. +
  196. .Properties of `sync`
  197. [%collapsible%open]
  198. ====
  199. //Begin time
  200. `time`:::
  201. (Required, object)
  202. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time]
  203. +
  204. .Properties of `time`
  205. [%collapsible%open]
  206. =====
  207. `delay`::::
  208. (Optional, <<time-units, time units>>)
  209. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-delay]
  210. `field`::::
  211. (Required, string)
  212. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-field]
  213. +
  214. --
  215. TIP: In general, it’s a good idea to use a field that contains the
  216. <<access-ingest-metadata,ingest timestamp>>. If you use a different field,
  217. you might need to set the `delay` such that it accounts for data transmission
  218. delays.
  219. --
  220. =====
  221. //End time
  222. ====
  223. //End sync
  224. [[put-transform-example]]
  225. == {api-examples-title}
  226. The following {transform} uses the `pivot` method:
  227. [source,console]
  228. --------------------------------------------------
  229. PUT _transform/ecommerce_transform1
  230. {
  231. "source": {
  232. "index": "kibana_sample_data_ecommerce",
  233. "query": {
  234. "term": {
  235. "geoip.continent_name": {
  236. "value": "Asia"
  237. }
  238. }
  239. }
  240. },
  241. "pivot": {
  242. "group_by": {
  243. "customer_id": {
  244. "terms": {
  245. "field": "customer_id"
  246. }
  247. }
  248. },
  249. "aggregations": {
  250. "max_price": {
  251. "max": {
  252. "field": "taxful_total_price"
  253. }
  254. }
  255. }
  256. },
  257. "description": "Maximum priced ecommerce data by customer_id in Asia",
  258. "dest": {
  259. "index": "kibana_sample_data_ecommerce_transform1",
  260. "pipeline": "add_timestamp_pipeline"
  261. },
  262. "frequency": "5m",
  263. "sync": {
  264. "time": {
  265. "field": "order_date",
  266. "delay": "60s"
  267. }
  268. },
  269. "retention_policy": {
  270. "time": {
  271. "field": "order_date",
  272. "max_age": "30d"
  273. }
  274. }
  275. }
  276. --------------------------------------------------
  277. // TEST[setup:kibana_sample_data_ecommerce,add_timestamp_pipeline]
  278. When the {transform} is created, you receive the following results:
  279. [source,console-result]
  280. ----
  281. {
  282. "acknowledged" : true
  283. }
  284. ----
  285. The following {transform} uses the `latest` method:
  286. [source,console]
  287. --------------------------------------------------
  288. PUT _transform/ecommerce_transform2
  289. {
  290. "source": {
  291. "index": "kibana_sample_data_ecommerce"
  292. },
  293. "latest": {
  294. "unique_key": ["customer_id"],
  295. "sort": "order_date"
  296. },
  297. "description": "Latest order for each customer",
  298. "dest": {
  299. "index": "kibana_sample_data_ecommerce_transform2"
  300. },
  301. "frequency": "5m",
  302. "sync": {
  303. "time": {
  304. "field": "order_date",
  305. "delay": "60s"
  306. }
  307. }
  308. }
  309. --------------------------------------------------
  310. // TEST[setup:kibana_sample_data_ecommerce]