preview-transform.asciidoc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. [role="child_attributes"]
  36. [[preview-transform-request-body]]
  37. == {api-request-body-title}
  38. `description`::
  39. (Optional, string) Free text description of the {transform}.
  40. //Begin dest
  41. `dest`::
  42. (Optional, object)
  43. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest]
  44. +
  45. .Properties of `dest`
  46. [%collapsible%open]
  47. ====
  48. `index`:::
  49. (Optional, string)
  50. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-index]
  51. `pipeline`:::
  52. (Optional, string)
  53. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=dest-pipeline]
  54. ====
  55. //End dest
  56. `frequency`::
  57. (Optional, <<time-units, time units>>)
  58. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=frequency]
  59. //Begin pivot
  60. `pivot`::
  61. (Required, object)
  62. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot]
  63. +
  64. .Properties of `pivot`
  65. [%collapsible%open]
  66. ====
  67. `aggregations` or `aggs`:::
  68. (Required, object)
  69. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-aggs]
  70. `group_by`:::
  71. (Required, object)
  72. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=pivot-group-by]
  73. ====
  74. //End pivot
  75. //Begin source
  76. `source`::
  77. (Required, object)
  78. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-transforms]
  79. +
  80. .Properties of `source`
  81. [%collapsible%open]
  82. ====
  83. `index`:::
  84. (Required, string or array)
  85. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-index-transforms]
  86. `query`:::
  87. (Optional, object)
  88. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=source-query-transforms]
  89. ====
  90. //End source
  91. //Begin sync
  92. `sync`::
  93. (Optional, object)
  94. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync]
  95. +
  96. .Properties of `sync`
  97. [%collapsible%open]
  98. ====
  99. //Begin sync.time
  100. `time`:::
  101. (Optional, object)
  102. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time]
  103. +
  104. .Properties of `analysis_config`
  105. [%collapsible%open]
  106. =====
  107. `delay`::::
  108. (Optional, <<time-units, time units>>)
  109. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-delay]
  110. `field`::::
  111. (Optional, string)
  112. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=sync-time-field]
  113. =====
  114. //End sync.time
  115. ====
  116. //End sync
  117. //Begin settings
  118. `settings`::
  119. (Optional, object)
  120. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings]
  121. +
  122. .Properties of `settings`
  123. [%collapsible%open]
  124. ====
  125. `docs_per_second`:::
  126. (Optional, float)
  127. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-docs-per-second]
  128. `max_page_search_size`:::
  129. (Optional, integer)
  130. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=transform-settings-max-page-search-size]
  131. ====
  132. //End settings
  133. [role="child_attributes"]
  134. [[preview-transform-response]]
  135. == {api-response-body-title}
  136. `preview`::
  137. (array) An array of documents. In particular, they are the JSON representation
  138. of the documents that would be created in the destination index by the
  139. {transform}.
  140. //Begin generated_dest_index
  141. `generated_dest_index`::
  142. (object) Contains details about the destination index.
  143. +
  144. .Properties of `generated_dest_index`
  145. [%collapsible%open]
  146. ====
  147. `aliases`:::
  148. (object) The aliases for the destination index.
  149. `mappings`:::
  150. (object) The <<mapping,mappings>> for each document in the destination index.
  151. `settings`:::
  152. (object) The <<index-modules-settings,index settings>> for the destination index.
  153. ====
  154. //End generated_dest_index
  155. == {api-examples-title}
  156. [source,console]
  157. --------------------------------------------------
  158. POST _transform/_preview
  159. {
  160. "source": {
  161. "index": "kibana_sample_data_ecommerce"
  162. },
  163. "pivot": {
  164. "group_by": {
  165. "customer_id": {
  166. "terms": {
  167. "field": "customer_id"
  168. }
  169. }
  170. },
  171. "aggregations": {
  172. "max_price": {
  173. "max": {
  174. "field": "taxful_total_price"
  175. }
  176. }
  177. }
  178. }
  179. }
  180. --------------------------------------------------
  181. // TEST[skip:set up sample data]
  182. The data that is returned for this example is as follows:
  183. [source,js]
  184. ----
  185. {
  186. "preview" : [
  187. {
  188. "max_price" : 171.0,
  189. "customer_id" : "10"
  190. },
  191. {
  192. "max_price" : 233.0,
  193. "customer_id" : "11"
  194. },
  195. {
  196. "max_price" : 200.0,
  197. "customer_id" : "12"
  198. }
  199. ...
  200. ],
  201. "generated_dest_index" : {
  202. "mappings" : {
  203. "_meta" : {
  204. "_transform" : {
  205. "transform" : "transform-preview",
  206. "version" : {
  207. "created" : "7.7.0"
  208. },
  209. "creation_date_in_millis" : 1584738236757
  210. },
  211. "created_by" : "transform"
  212. },
  213. "properties" : {
  214. "max_price" : {
  215. "type" : "half_float"
  216. },
  217. "customer_id" : {
  218. "type" : "keyword"
  219. }
  220. }
  221. },
  222. "settings" : {
  223. "index" : {
  224. "number_of_shards" : "1",
  225. "auto_expand_replicas" : "0-1"
  226. }
  227. },
  228. "aliases" : { }
  229. }
  230. }
  231. ----
  232. // NOTCONSOLE