preview-transform.asciidoc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 `manage_transform`
  16. cluster privileges to use this API. The built-in `transform_admin` role has
  17. these privileges. You must also have `read` and `view_index_metadata` privileges
  18. on the source index for the {transform}. For more information, see
  19. <<security-privileges>> and <<built-in-roles>>.
  20. [[preview-transform-desc]]
  21. ==== {api-description-title}
  22. This API generates a preview of the results that you will get when you run the
  23. <<put-transform,create {transforms} API>> with the same
  24. configuration. It returns a maximum of 100 results. The calculations are based
  25. on all the current data in the source index.
  26. It also generates a list of mappings and settings for the destination index.
  27. If the destination index does not exist when you start a {transform}, these are
  28. the mappings and settings that are used. These values are determined based on
  29. the field types of the source index and the {transform} aggregations.
  30. TIP: There are some <<transform-aggresponse-limitations,limitations>> that
  31. might result in poor mappings. As a work-around, create the destination index
  32. or an index template with your preferred mappings before you start the
  33. {transform}.
  34. [[preview-transform-request-body]]
  35. ==== {api-request-body-title}
  36. `description`::
  37. (Optional, string) Free text description of the {transform}.
  38. `dest`::
  39. (Optional, object)
  40. include::{docdir}/rest-api/common-parms.asciidoc[tag=dest]
  41. `dest`.`index`:::
  42. (Optional, string)
  43. include::{docdir}/rest-api/common-parms.asciidoc[tag=dest-index]
  44. `dest`.`pipeline`:::
  45. (Optional, string)
  46. include::{docdir}/rest-api/common-parms.asciidoc[tag=dest-pipeline]
  47. `frequency`::
  48. (Optional, <<time-units, time units>>)
  49. include::{docdir}/rest-api/common-parms.asciidoc[tag=frequency]
  50. `pivot`::
  51. (Required, object)
  52. include::{docdir}/rest-api/common-parms.asciidoc[tag=pivot]
  53. `pivot`.`aggregations` or `aggs`:::
  54. (Required, object)
  55. include::{docdir}/rest-api/common-parms.asciidoc[tag=pivot-aggs]
  56. `pivot`.`group_by`:::
  57. (Required, object)
  58. include::{docdir}/rest-api/common-parms.asciidoc[tag=pivot-group-by]
  59. `pivot`.`max_page_search_size`:::
  60. (Optional, integer)
  61. include::{docdir}/rest-api/common-parms.asciidoc[tag=pivot-max-page-search-size]
  62. `source`::
  63. (Required, object)
  64. include::{docdir}/rest-api/common-parms.asciidoc[tag=source-transforms]
  65. `source`.`index`:::
  66. (Required, string or array)
  67. include::{docdir}/rest-api/common-parms.asciidoc[tag=source-index-transforms]
  68. `source`.`query`:::
  69. (Optional, object)
  70. include::{docdir}/rest-api/common-parms.asciidoc[tag=source-query-transforms]
  71. `sync`::
  72. (Optional, object)
  73. include::{docdir}/rest-api/common-parms.asciidoc[tag=sync]
  74. `sync`.`time`:::
  75. (Optional, object)
  76. include::{docdir}/rest-api/common-parms.asciidoc[tag=sync-time]
  77. `sync`.`time`.`delay`::::
  78. (Optional, <<time-units, time units>>)
  79. include::{docdir}/rest-api/common-parms.asciidoc[tag=sync-time-delay]
  80. `sync`.`time`.`field`::::
  81. (Optional, string)
  82. include::{docdir}/rest-api/common-parms.asciidoc[tag=sync-time-field]
  83. [[preview-transform-response]]
  84. ==== {api-response-body-title}
  85. `preview`::
  86. (array) An array of documents. In particular, they are the JSON
  87. representation of the documents that would be created in the destination index
  88. by the {transform}.
  89. `generated_dest_index`::
  90. (object) Contains details about the destination index.
  91. `mappings`:::
  92. (object) The <<mapping,mappings>> for each document in the destination index.
  93. `settings`:::
  94. (object) The <<index-modules-settings,index settings>> for the destination
  95. index.
  96. `aliases`::: The aliases for the destination index.
  97. ==== {api-examples-title}
  98. [source,console]
  99. --------------------------------------------------
  100. POST _transform/_preview
  101. {
  102. "source": {
  103. "index": "kibana_sample_data_ecommerce"
  104. },
  105. "pivot": {
  106. "group_by": {
  107. "customer_id": {
  108. "terms": {
  109. "field": "customer_id"
  110. }
  111. }
  112. },
  113. "aggregations": {
  114. "max_price": {
  115. "max": {
  116. "field": "taxful_total_price"
  117. }
  118. }
  119. }
  120. }
  121. }
  122. --------------------------------------------------
  123. // TEST[skip:set up sample data]
  124. The data that is returned for this example is as follows:
  125. [source,js]
  126. ----
  127. {
  128. "preview" : [
  129. {
  130. "max_price" : 171.0,
  131. "customer_id" : "10"
  132. },
  133. {
  134. "max_price" : 233.0,
  135. "customer_id" : "11"
  136. },
  137. {
  138. "max_price" : 200.0,
  139. "customer_id" : "12"
  140. }
  141. ...
  142. ],
  143. "generated_dest_index" : {
  144. "mappings" : {
  145. "_meta" : {
  146. "_transform" : {
  147. "transform" : "transform-preview",
  148. "version" : {
  149. "created" : "7.7.0"
  150. },
  151. "creation_date_in_millis" : 1584738236757
  152. },
  153. "created_by" : "transform"
  154. },
  155. "properties" : {
  156. "max_price" : {
  157. "type" : "half_float"
  158. },
  159. "customer_id" : {
  160. "type" : "keyword"
  161. }
  162. }
  163. },
  164. "settings" : {
  165. "index" : {
  166. "number_of_shards" : "1",
  167. "auto_expand_replicas" : "0-1"
  168. }
  169. },
  170. "aliases" : { }
  171. }
  172. }
  173. ----
  174. // NOTCONSOLE