preview-transform.asciidoc 7.8 KB

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