preview-transform.asciidoc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[preview-transform]]
  4. === Preview {transforms} API
  5. [subs="attributes"]
  6. ++++
  7. <titleabbrev>Preview {transforms}</titleabbrev>
  8. ++++
  9. Previews a {transform}.
  10. beta[]
  11. [[preview-transform-request]]
  12. ==== {api-request-title}
  13. `POST _data_frame/transforms/_preview`
  14. [[preview-transform-prereq]]
  15. ==== {api-prereq-title}
  16. * If the {es} {security-features} are enabled, you must have
  17. `manage_data_frame_transforms` cluster privileges to use this API. The built-in
  18. `data_frame_transforms_admin` role has these privileges. You must also have
  19. `read` and `view_index_metadata` privileges on the source index for the
  20. {transform}. For more information, see
  21. {stack-ov}/security-privileges.html[Security privileges] and
  22. {stack-ov}/built-in-roles.html[Built-in roles].
  23. [[preview-transform-desc]]
  24. ==== {api-description-title}
  25. This API generates a preview of the results that you will get when you run the
  26. <<put-transform,create {transforms} API>> with the same
  27. configuration. It returns a maximum of 100 results. The calculations are based
  28. on all the current data in the source index.
  29. [[preview-transform-request-body]]
  30. ==== {api-request-body-title}
  31. `source`::
  32. (Required, object) The source configuration, which has the following
  33. properties:
  34. `index`:::
  35. (Required, string or array) The _source indices_ for the
  36. {transform}. It can be a single index, an index pattern (for
  37. example, `"myindex*"`), or an array of indices (for example,
  38. `["index1", "index2"]`).
  39. `query`:::
  40. (Optional, object) A query clause that retrieves a subset of data from the
  41. source index. See <<query-dsl>>.
  42. `pivot`::
  43. (Required, object) Defines the pivot function `group by` fields and the
  44. aggregation to reduce the data. See <<transform-pivot>>.
  45. [[preview-transform-response]]
  46. ==== {api-response-body-title}
  47. `preview`::
  48. (array) An array of documents. In particular, they are the JSON
  49. representation of the documents that would be created in the destination index
  50. by the {transform}.
  51. ==== {api-examples-title}
  52. [source,console]
  53. --------------------------------------------------
  54. POST _data_frame/transforms/_preview
  55. {
  56. "source": {
  57. "index": "kibana_sample_data_ecommerce"
  58. },
  59. "pivot": {
  60. "group_by": {
  61. "customer_id": {
  62. "terms": {
  63. "field": "customer_id"
  64. }
  65. }
  66. },
  67. "aggregations": {
  68. "max_price": {
  69. "max": {
  70. "field": "taxful_total_price"
  71. }
  72. }
  73. }
  74. }
  75. }
  76. --------------------------------------------------
  77. // TEST[skip:set up sample data]
  78. The data that is returned for this example is as follows:
  79. [source,js]
  80. ----
  81. {
  82. "preview" : [
  83. {
  84. "max_price" : 171.0,
  85. "customer_id" : "10"
  86. },
  87. {
  88. "max_price" : 233.0,
  89. "customer_id" : "11"
  90. },
  91. {
  92. "max_price" : 200.0,
  93. "customer_id" : "12"
  94. }
  95. ...
  96. ],
  97. "mappings": {
  98. "properties": {
  99. "max_price": {
  100. "type": "double"
  101. },
  102. "customer_id": {
  103. "type": "keyword"
  104. }
  105. }
  106. }
  107. }
  108. ----
  109. // NOTCONSOLE