preview-transform.asciidoc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. [role="xpack"]
  2. [[preview-transform]]
  3. = Preview {transform} API
  4. [subs="attributes"]
  5. ++++
  6. <titleabbrev>Preview {transform}</titleabbrev>
  7. ++++
  8. Previews a {transform}.
  9. [[preview-transform-request]]
  10. == {api-request-title}
  11. `GET _transform/<transform_id>/_preview` +
  12. `POST _transform/<transform_id>/_preview` +
  13. `GET _transform/_preview` +
  14. `POST _transform/_preview`
  15. [[preview-transform-prereq]]
  16. == {api-prereq-title}
  17. Requires the following privileges:
  18. * cluster: `manage_transform` (the `transform_admin` built-in role grants this
  19. privilege)
  20. * source indices: `read`, `view_index_metadata`.
  21. [[preview-transform-desc]]
  22. == {api-description-title}
  23. This API generates a preview of the results that you will get when you run the
  24. <<put-transform,create {transforms} API>> with the same
  25. configuration. It returns a maximum of 100 results. The calculations are based
  26. on all the current data in the source index.
  27. It also generates a list of mappings and settings for the destination index.
  28. If the destination index does not exist when you start a {transform}, these are
  29. the mappings and settings that are used. These values are determined based on
  30. the field types of the source index and the {transform} aggregations.
  31. TIP: There are some <<transform-aggresponse-limitations,limitations>> that
  32. might result in poor mappings. As a work-around, create the destination index
  33. or an index template with your preferred mappings before you start the
  34. {transform}.
  35. You must choose either the `latest` or `pivot` method for your {transform}; you
  36. cannot use both in a single {transform}.
  37. [role="child_attributes"]
  38. [[preview-transform-path-params]]
  39. == {api-path-parms-title}
  40. `<transform_id>`::
  41. (Optional, string)
  42. Id of the {transform} to preview.
  43. +
  44. NOTE: If you provide the `<transform_id>` as a path parameter, you cannot
  45. provide {transform} configuration details in the request body.
  46. [[preview-transform-query-parms]]
  47. == {api-query-parms-title}
  48. `timeout`::
  49. (Optional, time)
  50. Period to wait for a response. If no response is received before the timeout
  51. expires, the request fails and returns an error. Defaults to `30s`.
  52. [[preview-transform-request-body]]
  53. == {api-request-body-title}
  54. `description`::
  55. (Optional, string) Free text description of the {transform}.
  56. //Begin dest
  57. `dest`::
  58. (Optional, object)
  59. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest]
  60. +
  61. .Properties of `dest`
  62. [%collapsible%open]
  63. ====
  64. `index`:::
  65. (Optional, string)
  66. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-index]
  67. `pipeline`:::
  68. (Optional, string)
  69. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-pipeline]
  70. ====
  71. //End dest
  72. `frequency`::
  73. (Optional, <<time-units, time units>>)
  74. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=frequency]
  75. //Begin latest
  76. `latest`::
  77. (Required^*^, object)
  78. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-latest]
  79. +
  80. .Properties of `latest`
  81. [%collapsible%open]
  82. ====
  83. `sort`:::
  84. (Required, string)
  85. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-sort]
  86. `unique_key`:::
  87. (Required, array of strings)
  88. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-unique-key]
  89. ====
  90. //End latest
  91. //Begin pivot
  92. `pivot`::
  93. (Required, object)
  94. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot]
  95. +
  96. .Properties of `pivot`
  97. [%collapsible%open]
  98. ====
  99. `aggregations` or `aggs`:::
  100. (Required, object)
  101. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-aggs]
  102. `group_by`:::
  103. (Required, object)
  104. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-group-by]
  105. ====
  106. //End pivot
  107. //Begin retention policy
  108. `retention_policy`::
  109. (Optional, object)
  110. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention]
  111. +
  112. .Properties of `retention_policy`
  113. [%collapsible%open]
  114. ====
  115. `time`:::
  116. (Required, object)
  117. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time]
  118. +
  119. .Properties of `time`
  120. [%collapsible%open]
  121. =====
  122. `field`:::
  123. (Required, string)
  124. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time-field]
  125. `max_age`:::
  126. (Required, <<time-units, time units>>)
  127. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time-max-age]
  128. =====
  129. ====
  130. //End retention policy
  131. //Begin source
  132. `source`::
  133. (Required, object)
  134. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-transforms]
  135. +
  136. .Properties of `source`
  137. [%collapsible%open]
  138. ====
  139. `index`:::
  140. (Required, string or array)
  141. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-index-transforms]
  142. `query`:::
  143. (Optional, object)
  144. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-query-transforms]
  145. `runtime_mappings`:::
  146. (Optional, object)
  147. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-runtime-mappings-transforms]
  148. ====
  149. //End source
  150. //Begin sync
  151. `sync`::
  152. (Optional, object)
  153. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync]
  154. +
  155. .Properties of `sync`
  156. [%collapsible%open]
  157. ====
  158. //Begin sync.time
  159. `time`:::
  160. (Optional, object)
  161. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time]
  162. +
  163. .Properties of `analysis_config`
  164. [%collapsible%open]
  165. =====
  166. `delay`::::
  167. (Optional, <<time-units, time units>>)
  168. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-delay]
  169. `field`::::
  170. (Optional, string)
  171. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-field]
  172. =====
  173. //End sync.time
  174. ====
  175. //End sync
  176. //Begin settings
  177. `settings`::
  178. (Optional, object)
  179. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings]
  180. +
  181. .Properties of `settings`
  182. [%collapsible%open]
  183. ====
  184. `dates_as_epoch_millis`:::
  185. (Optional, boolean)
  186. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-dates-as-epoch-milli]
  187. `docs_per_second`:::
  188. (Optional, float)
  189. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-docs-per-second]
  190. `align_checkpoints`:::
  191. (Optional, boolean)
  192. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-align-checkpoints]
  193. `deduce_mappings`:::
  194. (Optional, boolean)
  195. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-deduce-mappings]
  196. `max_page_search_size`:::
  197. (Optional, integer)
  198. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-max-page-search-size]
  199. ====
  200. //End settings
  201. [role="child_attributes"]
  202. [[preview-transform-response]]
  203. == {api-response-body-title}
  204. `preview`::
  205. (array) An array of documents. In particular, they are the JSON representation
  206. of the documents that would be created in the destination index by the
  207. {transform}.
  208. //Begin generated_dest_index
  209. `generated_dest_index`::
  210. (object) Contains details about the destination index.
  211. +
  212. .Properties of `generated_dest_index`
  213. [%collapsible%open]
  214. ====
  215. `aliases`:::
  216. (object) The aliases for the destination index.
  217. `mappings`:::
  218. (object) The <<mapping,mappings>> for each document in the destination index.
  219. `settings`:::
  220. (object) The <<index-modules-settings,index settings>> for the destination index.
  221. ====
  222. //End generated_dest_index
  223. == {api-examples-title}
  224. [source,console]
  225. --------------------------------------------------
  226. POST _transform/_preview
  227. {
  228. "source": {
  229. "index": "kibana_sample_data_ecommerce"
  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. }
  248. --------------------------------------------------
  249. // TEST[skip:set up sample data]
  250. The data that is returned for this example is as follows:
  251. [source,js]
  252. ----
  253. {
  254. "preview" : [
  255. {
  256. "max_price" : 171.0,
  257. "customer_id" : "10"
  258. },
  259. {
  260. "max_price" : 233.0,
  261. "customer_id" : "11"
  262. },
  263. {
  264. "max_price" : 200.0,
  265. "customer_id" : "12"
  266. }
  267. ...
  268. ],
  269. "generated_dest_index" : {
  270. "mappings" : {
  271. "_meta" : {
  272. "_transform" : {
  273. "transform" : "transform-preview",
  274. "version" : {
  275. "created" : "7.7.0"
  276. },
  277. "creation_date_in_millis" : 1584738236757
  278. },
  279. "created_by" : "transform"
  280. },
  281. "properties" : {
  282. "max_price" : {
  283. "type" : "half_float"
  284. },
  285. "customer_id" : {
  286. "type" : "keyword"
  287. }
  288. }
  289. },
  290. "settings" : {
  291. "index" : {
  292. "number_of_shards" : "1",
  293. "auto_expand_replicas" : "0-1"
  294. }
  295. },
  296. "aliases" : { }
  297. }
  298. }
  299. ----
  300. // NOTCONSOLE