preview-transform.asciidoc 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. `docs_per_second`:::
  185. (Optional, float)
  186. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-docs-per-second]
  187. `align_checkpoints`:::
  188. (Optional, boolean)
  189. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-align-checkpoints]
  190. `max_page_search_size`:::
  191. (Optional, integer)
  192. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-max-page-search-size]
  193. ====
  194. //End settings
  195. [role="child_attributes"]
  196. [[preview-transform-response]]
  197. == {api-response-body-title}
  198. `preview`::
  199. (array) An array of documents. In particular, they are the JSON representation
  200. of the documents that would be created in the destination index by the
  201. {transform}.
  202. //Begin generated_dest_index
  203. `generated_dest_index`::
  204. (object) Contains details about the destination index.
  205. +
  206. .Properties of `generated_dest_index`
  207. [%collapsible%open]
  208. ====
  209. `aliases`:::
  210. (object) The aliases for the destination index.
  211. `mappings`:::
  212. (object) The <<mapping,mappings>> for each document in the destination index.
  213. `settings`:::
  214. (object) The <<index-modules-settings,index settings>> for the destination index.
  215. ====
  216. //End generated_dest_index
  217. == {api-examples-title}
  218. [source,console]
  219. --------------------------------------------------
  220. POST _transform/_preview
  221. {
  222. "source": {
  223. "index": "kibana_sample_data_ecommerce"
  224. },
  225. "pivot": {
  226. "group_by": {
  227. "customer_id": {
  228. "terms": {
  229. "field": "customer_id"
  230. }
  231. }
  232. },
  233. "aggregations": {
  234. "max_price": {
  235. "max": {
  236. "field": "taxful_total_price"
  237. }
  238. }
  239. }
  240. }
  241. }
  242. --------------------------------------------------
  243. // TEST[skip:set up sample data]
  244. The data that is returned for this example is as follows:
  245. [source,js]
  246. ----
  247. {
  248. "preview" : [
  249. {
  250. "max_price" : 171.0,
  251. "customer_id" : "10"
  252. },
  253. {
  254. "max_price" : 233.0,
  255. "customer_id" : "11"
  256. },
  257. {
  258. "max_price" : 200.0,
  259. "customer_id" : "12"
  260. }
  261. ...
  262. ],
  263. "generated_dest_index" : {
  264. "mappings" : {
  265. "_meta" : {
  266. "_transform" : {
  267. "transform" : "transform-preview",
  268. "version" : {
  269. "created" : "7.7.0"
  270. },
  271. "creation_date_in_millis" : 1584738236757
  272. },
  273. "created_by" : "transform"
  274. },
  275. "properties" : {
  276. "max_price" : {
  277. "type" : "half_float"
  278. },
  279. "customer_id" : {
  280. "type" : "keyword"
  281. }
  282. }
  283. },
  284. "settings" : {
  285. "index" : {
  286. "number_of_shards" : "1",
  287. "auto_expand_replicas" : "0-1"
  288. }
  289. },
  290. "aliases" : { }
  291. }
  292. }
  293. ----
  294. // NOTCONSOLE