put-dfanalytics.asciidoc 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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-supported-fields]]
  36. ===== Supported fields
  37. ====== {oldetection-cap}
  38. {oldetection-cap} requires numeric or boolean data to analyze. The algorithms
  39. don't support missing values therefore fields that have data types other than
  40. numeric or boolean are ignored. Documents where included fields contain missing
  41. values, null values, or an array are also ignored. Therefore the `dest` index
  42. may contain documents that don't have an {olscore}.
  43. ====== {regression-cap}
  44. {regression-cap} supports fields that are numeric, boolean, text, keyword and ip. It
  45. is also tolerant of missing values. Fields that are supported are included in
  46. the analysis, other fields are ignored. Documents where included fields contain
  47. an array with two or more values are also ignored. Documents in the `dest` index
  48. that don’t contain a results field are not included in the {reganalysis}.
  49. [[ml-put-dfanalytics-path-params]]
  50. ==== {api-path-parms-title}
  51. `<data_frame_analytics_id>`::
  52. (Required, string) A numerical character string that uniquely identifies the
  53. {dfanalytics-job}. This identifier can contain lowercase alphanumeric
  54. characters (a-z and 0-9), hyphens, and underscores. It must start and end with
  55. alphanumeric characters.
  56. [[ml-put-dfanalytics-request-body]]
  57. ==== {api-request-body-title}
  58. `analysis`::
  59. (Required, object) Defines the type of {dfanalytics} you want to perform on
  60. your source index. For example: `outlier_detection`. See
  61. <<dfanalytics-types>>.
  62. `analyzed_fields`::
  63. (Optional, object) You can specify both `includes` and/or `excludes` patterns.
  64. If `analyzed_fields` is not set, only the relevant fields will be included.
  65. For example, all the numeric fields for {oldetection}. For the supported field
  66. types, see <<ml-put-dfanalytics-supported-fields>>.
  67. `includes`:::
  68. (Optional, array) An array of strings that defines the fields that will be
  69. included in the analysis.
  70. `excludes`:::
  71. (Optional, array) An array of strings that defines the fields that will be
  72. excluded from the analysis.
  73. `description`::
  74. (Optional, string) A description of the job.
  75. `dest`::
  76. (Required, object) The destination configuration, consisting of `index` and
  77. optionally `results_field` (`ml` by default).
  78. `index`:::
  79. (Required, string) Defines the _destination index_ to store the results of
  80. the {dfanalytics-job}.
  81. `results_field`:::
  82. (Optional, string) Defines the name of the field in which to store the
  83. results of the analysis. Default to `ml`.
  84. `model_memory_limit`::
  85. (Optional, string) The approximate maximum amount of memory resources that are
  86. permitted for analytical processing. The default value for {dfanalytics-jobs}
  87. is `1gb`. If your `elasticsearch.yml` file contains an
  88. `xpack.ml.max_model_memory_limit` setting, an error occurs when you try to
  89. create {dfanalytics-jobs} that have `model_memory_limit` values greater than
  90. that setting. For more information, see <<ml-settings>>.
  91. `source`::
  92. (Required, object) The source configuration, consisting of `index` and
  93. optionally a `query`.
  94. `index`:::
  95. (Required, string or array) Index or indices on which to perform the
  96. analysis. It can be a single index or index pattern as well as an array of
  97. indices or patterns.
  98. `query`:::
  99. (Optional, object) The {es} query domain-specific language
  100. (<<query-dsl,DSL>>). This value corresponds to the query object in an {es}
  101. search POST body. All the options that are supported by {es} can be used,
  102. as this object is passed verbatim to {es}. By default, this property has
  103. the following value: `{"match_all": {}}`.
  104. [[ml-put-dfanalytics-example]]
  105. ==== {api-examples-title}
  106. [[ml-put-dfanalytics-example-od]]
  107. ===== {oldetection-cap} example
  108. The following example creates the `loganalytics` {dfanalytics-job}, the analysis
  109. type is `outlier_detection`:
  110. [source,console]
  111. --------------------------------------------------
  112. PUT _ml/data_frame/analytics/loganalytics
  113. {
  114. "description": "Outlier detection on log data",
  115. "source": {
  116. "index": "logdata"
  117. },
  118. "dest": {
  119. "index": "logdata_out"
  120. },
  121. "analysis": {
  122. "outlier_detection": {
  123. "compute_feature_influence": true,
  124. "outlier_fraction": 0.05,
  125. "standardization_enabled": true
  126. }
  127. }
  128. }
  129. --------------------------------------------------
  130. // TEST[setup:setup_logdata]
  131. The API returns the following result:
  132. [source,console-result]
  133. ----
  134. {
  135. "id": "loganalytics",
  136. "description": "Outlier detection on log data",
  137. "source": {
  138. "index": ["logdata"],
  139. "query": {
  140. "match_all": {}
  141. }
  142. },
  143. "dest": {
  144. "index": "logdata_out",
  145. "results_field": "ml"
  146. },
  147. "analysis": {
  148. "outlier_detection": {
  149. "compute_feature_influence": true,
  150. "outlier_fraction": 0.05,
  151. "standardization_enabled": true
  152. }
  153. },
  154. "model_memory_limit": "1gb",
  155. "create_time" : 1562265491319,
  156. "version" : "8.0.0"
  157. }
  158. ----
  159. // TESTRESPONSE[s/1562265491319/$body.$_path/]
  160. // TESTRESPONSE[s/"version": "8.0.0"/"version": $body.version/]
  161. [[ml-put-dfanalytics-example-r]]
  162. ===== {regression-cap} examples
  163. The following example creates the `house_price_regression_analysis`
  164. {dfanalytics-job}, the analysis type is `regression`:
  165. [source,console]
  166. --------------------------------------------------
  167. PUT _ml/data_frame/analytics/house_price_regression_analysis
  168. {
  169. "source": {
  170. "index": "houses_sold_last_10_yrs"
  171. },
  172. "dest": {
  173. "index": "house_price_predictions"
  174. },
  175. "analysis":
  176. {
  177. "regression": {
  178. "dependent_variable": "price"
  179. }
  180. }
  181. }
  182. --------------------------------------------------
  183. // TEST[skip:TBD]
  184. The API returns the following result:
  185. [source,console-result]
  186. ----
  187. {
  188. "id" : "house_price_regression_analysis",
  189. "source" : {
  190. "index" : [
  191. "houses_sold_last_10_yrs"
  192. ],
  193. "query" : {
  194. "match_all" : { }
  195. }
  196. },
  197. "dest" : {
  198. "index" : "house_price_predictions",
  199. "results_field" : "ml"
  200. },
  201. "analysis" : {
  202. "regression" : {
  203. "dependent_variable" : "price",
  204. "training_percent" : 100
  205. }
  206. },
  207. "model_memory_limit" : "1gb",
  208. "create_time" : 1567168659127,
  209. "version" : "8.0.0"
  210. }
  211. ----
  212. // TESTRESPONSE[s/1567168659127/$body.$_path/]
  213. // TESTRESPONSE[s/"version": "8.0.0"/"version": $body.version/]
  214. The following example creates a job and specifies a training percent:
  215. [source,console]
  216. --------------------------------------------------
  217. PUT _ml/data_frame/analytics/student_performance_mathematics_0.3
  218. {
  219. "source": {
  220. "index": "student_performance_mathematics"
  221. },
  222. "dest": {
  223. "index":"student_performance_mathematics_reg"
  224. },
  225. "analysis":
  226. {
  227. "regression": {
  228. "dependent_variable": "G3",
  229. "training_percent": 70 <1>
  230. }
  231. }
  232. }
  233. --------------------------------------------------
  234. // TEST[skip:TBD]
  235. <1> The `training_percent` defines the percentage of the data set that will be used
  236. for training the model.