preview-transform.asciidoc 7.4 KB

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