put-dfanalytics.asciidoc 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. [role="xpack"]
  2. [testenv="platinum"]
  3. [[put-dfanalytics]]
  4. === Create {dfanalytics-jobs} API
  5. [subs="attributes"]
  6. ++++
  7. <titleabbrev>Create {dfanalytics-jobs}</titleabbrev>
  8. ++++
  9. Instantiates a {dfanalytics-job}.
  10. experimental[]
  11. [[ml-put-dfanalytics-request]]
  12. ==== {api-request-title}
  13. `PUT _ml/data_frame/analytics/<data_frame_analytics_id>`
  14. [[ml-put-dfanalytics-prereq]]
  15. ==== {api-prereq-title}
  16. * You must have `machine_learning_admin` built-in role to use this API. You must
  17. also have `read` and `view_index_metadata` privileges on the source index and
  18. `read`, `create_index`, and `index` privileges on the destination index. For
  19. more information, see <<security-privileges>> and <<built-in-roles>>.
  20. [[ml-put-dfanalytics-desc]]
  21. ==== {api-description-title}
  22. This API creates a {dfanalytics-job} that performs an analysis on the source
  23. index and stores the outcome in a destination index.
  24. The destination index will be automatically created if it does not exist. The
  25. `index.number_of_shards` and `index.number_of_replicas` settings of the source
  26. index will be copied over the destination index. When the source index matches
  27. multiple indices, these settings will be set to the maximum values found in the
  28. source indices.
  29. The mappings of the source indices are also attempted to be copied over
  30. to the destination index, however, if the mappings of any of the fields don't
  31. match among the source indices, the attempt will fail with an error message.
  32. If the destination index already exists, then it will be use as is. This makes
  33. it possible to set up the destination index in advance with custom settings
  34. and mappings.
  35. [[ml-put-dfanalytics-path-params]]
  36. ==== {api-path-parms-title}
  37. `<data_frame_analytics_id>`::
  38. (Required, string) A numerical character string that uniquely identifies the
  39. {dfanalytics-job}. This identifier can contain lowercase alphanumeric
  40. characters (a-z and 0-9), hyphens, and underscores. It must start and end with
  41. alphanumeric characters.
  42. [[ml-put-dfanalytics-request-body]]
  43. ==== {api-request-body-title}
  44. `analysis`::
  45. (Required, object) Defines the type of {dfanalytics} you want to perform on your source
  46. index. For example: `outlier_detection`. See <<dfanalytics-types>>.
  47. `analyzed_fields`::
  48. (Optional, object) You can specify both `includes` and/or `excludes` patterns.
  49. If `analyzed_fields` is not set, only the relevant fields will be included.
  50. For example, all the numeric fields for {oldetection}.
  51. `analyzed_fields.includes`:::
  52. (Optional, array) An array of strings that defines the fields that will be
  53. included in the analysis.
  54. `analyzed_fields.excludes`:::
  55. (Optional, array) An array of strings that defines the fields that will be
  56. excluded from the analysis.
  57. `description`::
  58. (Optional, string) A description of the job.
  59. `dest`::
  60. (Required, object) The destination configuration, consisting of `index` and
  61. optionally `results_field` (`ml` by default).
  62. `index`:::
  63. (Required, string) Defines the _destination index_ to store the results of
  64. the {dfanalytics-job}.
  65. `results_field`:::
  66. (Optional, string) Defines the name of the field in which to store the
  67. results of the analysis. Default to `ml`.
  68. `model_memory_limit`::
  69. (Optional, string) The approximate maximum amount of memory resources that are
  70. permitted for analytical processing. The default value for {dfanalytics-jobs}
  71. is `1gb`. If your `elasticsearch.yml` file contains an
  72. `xpack.ml.max_model_memory_limit` setting, an error occurs when you try to
  73. create {dfanalytics-jobs} that have `model_memory_limit` values greater than
  74. that setting. For more information, see <<ml-settings>>.
  75. `source`::
  76. (Required, object) The source configuration, consisting of `index` and
  77. optionally a `query`.
  78. `index`:::
  79. (Required, string or array) Index or indices on which to perform the
  80. analysis. It can be a single index or index pattern as well as an array of
  81. indices or patterns.
  82. `query`:::
  83. (Optional, object) The {es} query domain-specific language
  84. (<<query-dsl,DSL>>). This value corresponds to the query object in an {es}
  85. search POST body. All the options that are supported by {es} can be used,
  86. as this object is passed verbatim to {es}. By default, this property has
  87. the following value: `{"match_all": {}}`.
  88. [[ml-put-dfanalytics-example]]
  89. ==== {api-examples-title}
  90. [[ml-put-dfanalytics-example-od]]
  91. ===== {oldetection-cap} example
  92. The following example creates the `loganalytics` {dfanalytics-job}, the analysis
  93. type is `outlier_detection`:
  94. [source,console]
  95. --------------------------------------------------
  96. PUT _ml/data_frame/analytics/loganalytics
  97. {
  98. "description": "Outlier detection on log data",
  99. "source": {
  100. "index": "logdata"
  101. },
  102. "dest": {
  103. "index": "logdata_out"
  104. },
  105. "analysis": {
  106. "outlier_detection": {
  107. }
  108. }
  109. }
  110. --------------------------------------------------
  111. // TEST[setup:setup_logdata]
  112. The API returns the following result:
  113. [source,console-result]
  114. ----
  115. {
  116. "id": "loganalytics",
  117. "description": "Outlier detection on log data",
  118. "source": {
  119. "index": ["logdata"],
  120. "query": {
  121. "match_all": {}
  122. }
  123. },
  124. "dest": {
  125. "index": "logdata_out",
  126. "results_field": "ml"
  127. },
  128. "analysis": {
  129. "outlier_detection": {}
  130. },
  131. "model_memory_limit": "1gb",
  132. "create_time" : 1562265491319,
  133. "version" : "8.0.0"
  134. }
  135. ----
  136. // TESTRESPONSE[s/1562265491319/$body.$_path/]
  137. // TESTRESPONSE[s/"version": "8.0.0"/"version": $body.version/]
  138. [[ml-put-dfanalytics-example-r]]
  139. ===== {regression-cap} examples
  140. The following example creates the `house_price_regression_analysis`
  141. {dfanalytics-job}, the analysis type is `regression`:
  142. [source,console]
  143. --------------------------------------------------
  144. PUT _ml/data_frame/analytics/house_price_regression_analysis
  145. {
  146. "source": {
  147. "index": "houses_sold_last_10_yrs"
  148. },
  149. "dest": {
  150. "index": "house_price_predictions"
  151. },
  152. "analysis":
  153. {
  154. "regression": {
  155. "dependent_variable": "price"
  156. }
  157. }
  158. }
  159. --------------------------------------------------
  160. // TEST[skip:TBD]
  161. The API returns the following result:
  162. [source,console-result]
  163. ----
  164. {
  165. "id" : "house_price_regression_analysis",
  166. "source" : {
  167. "index" : [
  168. "houses_sold_last_10_yrs"
  169. ],
  170. "query" : {
  171. "match_all" : { }
  172. }
  173. },
  174. "dest" : {
  175. "index" : "house_price_predictions",
  176. "results_field" : "ml"
  177. },
  178. "analysis" : {
  179. "regression" : {
  180. "dependent_variable" : "price",
  181. "training_percent" : 100
  182. }
  183. },
  184. "model_memory_limit" : "1gb",
  185. "create_time" : 1567168659127,
  186. "version" : "8.0.0"
  187. }
  188. ----
  189. // TESTRESPONSE[s/1567168659127/$body.$_path/]
  190. // TESTRESPONSE[s/"version": "8.0.0"/"version": $body.version/]
  191. The following example creates a job and specifies a training percent:
  192. [source,console]
  193. --------------------------------------------------
  194. PUT _ml/data_frame/analytics/student_performance_mathematics_0.3
  195. {
  196. "source": {
  197. "index": "student_performance_mathematics"
  198. },
  199. "dest": {
  200. "index":"student_performance_mathematics_reg"
  201. },
  202. "analysis":
  203. {
  204. "regression": {
  205. "dependent_variable": "G3",
  206. "training_percent": 70 <1>
  207. }
  208. }
  209. }
  210. --------------------------------------------------
  211. // TEST[skip:TBD]
  212. <1> The `training_percent` defines the percentage of the data set that will be used
  213. for training the model.