preview-transform.asciidoc 6.8 KB

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