preview-transform.asciidoc 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. `POST _transform/_preview`
  13. [[preview-transform-prereq]]
  14. == {api-prereq-title}
  15. If the {es} {security-features} are enabled, you must have the following
  16. privileges:
  17. * `manage_transform`
  18. * source index: `read`, `view_index_metadata`
  19. The built-in `transform_admin` role has the `manage_transform` privilege.
  20. For more information, see <<security-privileges>> and <<built-in-roles>>.
  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-request-body]]
  39. == {api-request-body-title}
  40. `description`::
  41. (Optional, string) Free text description of the {transform}.
  42. //Begin dest
  43. `dest`::
  44. (Optional, object)
  45. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest]
  46. +
  47. .Properties of `dest`
  48. [%collapsible%open]
  49. ====
  50. `index`:::
  51. (Optional, string)
  52. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-index]
  53. `pipeline`:::
  54. (Optional, string)
  55. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-pipeline]
  56. ====
  57. //End dest
  58. `frequency`::
  59. (Optional, <<time-units, time units>>)
  60. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=frequency]
  61. //Begin latest
  62. `latest`::
  63. (Required^*^, object)
  64. beta:[]
  65. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-latest]
  66. +
  67. .Properties of `latest`
  68. [%collapsible%open]
  69. ====
  70. `sort`:::
  71. (Required, string)
  72. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-sort]
  73. `unique_key`:::
  74. (Required, array of strings)
  75. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-unique-key]
  76. ====
  77. //End latest
  78. //Begin pivot
  79. `pivot`::
  80. (Required, object)
  81. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot]
  82. +
  83. .Properties of `pivot`
  84. [%collapsible%open]
  85. ====
  86. `aggregations` or `aggs`:::
  87. (Required, object)
  88. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-aggs]
  89. `group_by`:::
  90. (Required, object)
  91. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-group-by]
  92. ====
  93. //End pivot
  94. //Begin retention policy
  95. `retention_policy`::
  96. (Optional, object)
  97. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention]
  98. +
  99. .Properties of `retention_policy`
  100. [%collapsible%open]
  101. ====
  102. `time`:::
  103. (Required, object)
  104. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time]
  105. +
  106. .Properties of `time`
  107. [%collapsible%open]
  108. =====
  109. `field`:::
  110. (Required, string)
  111. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time-field]
  112. `max_age`:::
  113. (Required, <<time-units, time units>>)
  114. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-retention-time-max-age]
  115. =====
  116. ====
  117. //End retention policy
  118. //Begin source
  119. `source`::
  120. (Required, object)
  121. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-transforms]
  122. +
  123. .Properties of `source`
  124. [%collapsible%open]
  125. ====
  126. `index`:::
  127. (Required, string or array)
  128. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-index-transforms]
  129. `query`:::
  130. (Optional, object)
  131. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-query-transforms]
  132. `runtime_mappings`:::
  133. (Optional, object)
  134. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-runtime-mappings-transforms]
  135. ====
  136. //End source
  137. //Begin sync
  138. `sync`::
  139. (Optional, object)
  140. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync]
  141. +
  142. .Properties of `sync`
  143. [%collapsible%open]
  144. ====
  145. //Begin sync.time
  146. `time`:::
  147. (Optional, object)
  148. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time]
  149. +
  150. .Properties of `analysis_config`
  151. [%collapsible%open]
  152. =====
  153. `delay`::::
  154. (Optional, <<time-units, time units>>)
  155. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-delay]
  156. `field`::::
  157. (Optional, string)
  158. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-field]
  159. =====
  160. //End sync.time
  161. ====
  162. //End sync
  163. //Begin settings
  164. `settings`::
  165. (Optional, object)
  166. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings]
  167. +
  168. .Properties of `settings`
  169. [%collapsible%open]
  170. ====
  171. `docs_per_second`:::
  172. (Optional, float)
  173. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-docs-per-second]
  174. `max_page_search_size`:::
  175. (Optional, integer)
  176. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-max-page-search-size]
  177. ====
  178. //End settings
  179. [role="child_attributes"]
  180. [[preview-transform-response]]
  181. == {api-response-body-title}
  182. `preview`::
  183. (array) An array of documents. In particular, they are the JSON representation
  184. of the documents that would be created in the destination index by the
  185. {transform}.
  186. //Begin generated_dest_index
  187. `generated_dest_index`::
  188. (object) Contains details about the destination index.
  189. +
  190. .Properties of `generated_dest_index`
  191. [%collapsible%open]
  192. ====
  193. `aliases`:::
  194. (object) The aliases for the destination index.
  195. `mappings`:::
  196. (object) The <<mapping,mappings>> for each document in the destination index.
  197. `settings`:::
  198. (object) The <<index-modules-settings,index settings>> for the destination index.
  199. ====
  200. //End generated_dest_index
  201. == {api-examples-title}
  202. [source,console]
  203. --------------------------------------------------
  204. POST _transform/_preview
  205. {
  206. "source": {
  207. "index": "kibana_sample_data_ecommerce"
  208. },
  209. "pivot": {
  210. "group_by": {
  211. "customer_id": {
  212. "terms": {
  213. "field": "customer_id"
  214. }
  215. }
  216. },
  217. "aggregations": {
  218. "max_price": {
  219. "max": {
  220. "field": "taxful_total_price"
  221. }
  222. }
  223. }
  224. }
  225. }
  226. --------------------------------------------------
  227. // TEST[skip:set up sample data]
  228. The data that is returned for this example is as follows:
  229. [source,js]
  230. ----
  231. {
  232. "preview" : [
  233. {
  234. "max_price" : 171.0,
  235. "customer_id" : "10"
  236. },
  237. {
  238. "max_price" : 233.0,
  239. "customer_id" : "11"
  240. },
  241. {
  242. "max_price" : 200.0,
  243. "customer_id" : "12"
  244. }
  245. ...
  246. ],
  247. "generated_dest_index" : {
  248. "mappings" : {
  249. "_meta" : {
  250. "_transform" : {
  251. "transform" : "transform-preview",
  252. "version" : {
  253. "created" : "7.7.0"
  254. },
  255. "creation_date_in_millis" : 1584738236757
  256. },
  257. "created_by" : "transform"
  258. },
  259. "properties" : {
  260. "max_price" : {
  261. "type" : "half_float"
  262. },
  263. "customer_id" : {
  264. "type" : "keyword"
  265. }
  266. }
  267. },
  268. "settings" : {
  269. "index" : {
  270. "number_of_shards" : "1",
  271. "auto_expand_replicas" : "0-1"
  272. }
  273. },
  274. "aliases" : { }
  275. }
  276. }
  277. ----
  278. // NOTCONSOLE