put-dfanalytics.asciidoc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. ====== {classification-cap}
  50. {classification-cap} supports fields that are numeric, boolean, text, keyword
  51. and ip. It is also tolerant of missing values. Fields that are supported are
  52. included in the analysis, other fields are ignored. Documents where included
  53. fields contain an array with two or more values are also ignored. Documents in
  54. the `dest` index that don’t contain a results field are not included in the
  55. {classanalysis}.
  56. {classanalysis-cap} can be improved by mapping ordinal variable values to a
  57. single number. For example, in case of age ranges, you can model the values as
  58. "0-14" = 0, "15-24" = 1, "25-34" = 2, and so on.
  59. [[ml-put-dfanalytics-path-params]]
  60. ==== {api-path-parms-title}
  61. `<data_frame_analytics_id>`::
  62. (Required, string) A numerical character string that uniquely identifies the
  63. {dfanalytics-job}. This identifier can contain lowercase alphanumeric
  64. characters (a-z and 0-9), hyphens, and underscores. It must start and end with
  65. alphanumeric characters.
  66. [[ml-put-dfanalytics-request-body]]
  67. ==== {api-request-body-title}
  68. `analysis`::
  69. (Required, object) Defines the type of {dfanalytics} you want to perform on
  70. your source index. For example: `outlier_detection`. See
  71. <<dfanalytics-types>>.
  72. `analyzed_fields`::
  73. (Optional, object) You can specify both `includes` and/or `excludes` patterns.
  74. If `analyzed_fields` is not set, only the relevant fields will be included.
  75. For example, all the numeric fields for {oldetection}. For the supported field
  76. types, see <<ml-put-dfanalytics-supported-fields>>. If you specify fields –
  77. either in `includes` or in `excludes` – that have a data type that is not
  78. supported, an error occurs.
  79. `includes`:::
  80. (Optional, array) An array of strings that defines the fields that will be
  81. included in the analysis.
  82. `excludes`:::
  83. (Optional, array) An array of strings that defines the fields that will be
  84. excluded from the analysis. You do not need to add fields with unsupported
  85. data types to `excludes`, these fields are excluded from the analysis
  86. automatically.
  87. `description`::
  88. (Optional, string) A description of the job.
  89. `dest`::
  90. (Required, object) The destination configuration, consisting of `index` and
  91. optionally `results_field` (`ml` by default).
  92. `index`:::
  93. (Required, string) Defines the _destination index_ to store the results of
  94. the {dfanalytics-job}.
  95. `results_field`:::
  96. (Optional, string) Defines the name of the field in which to store the
  97. results of the analysis. Default to `ml`.
  98. `model_memory_limit`::
  99. (Optional, string) The approximate maximum amount of memory resources that are
  100. permitted for analytical processing. The default value for {dfanalytics-jobs}
  101. is `1gb`. If your `elasticsearch.yml` file contains an
  102. `xpack.ml.max_model_memory_limit` setting, an error occurs when you try to
  103. create {dfanalytics-jobs} that have `model_memory_limit` values greater than
  104. that setting. For more information, see <<ml-settings>>.
  105. `source`::
  106. (Required, object) The source configuration, consisting of `index` and
  107. optionally a `query`.
  108. `index`:::
  109. (Required, string or array) Index or indices on which to perform the
  110. analysis. It can be a single index or index pattern as well as an array of
  111. indices or patterns.
  112. `query`:::
  113. (Optional, object) The {es} query domain-specific language
  114. (<<query-dsl,DSL>>). This value corresponds to the query object in an {es}
  115. search POST body. All the options that are supported by {es} can be used,
  116. as this object is passed verbatim to {es}. By default, this property has
  117. the following value: `{"match_all": {}}`.
  118. `allow_lazy_start`::
  119. (Optional, boolean) Whether this job should be allowed to start when there
  120. is insufficient {ml} node capacity for it to be immediately assigned to a node.
  121. The default is `false`, which means that the <<start-dfanalytics>>
  122. will return an error if a {ml} node with capacity to run the
  123. job cannot immediately be found. (However, this is also subject to
  124. the cluster-wide `xpack.ml.max_lazy_ml_nodes` setting - see
  125. <<advanced-ml-settings>>.) If this option is set to `true` then
  126. the <<start-dfanalytics>> will not return an error, and the job will
  127. wait in the `starting` state until sufficient {ml} node capacity
  128. is available.
  129. [[ml-put-dfanalytics-example]]
  130. ==== {api-examples-title}
  131. [[ml-put-dfanalytics-example-od]]
  132. ===== {oldetection-cap} example
  133. The following example creates the `loganalytics` {dfanalytics-job}, the analysis
  134. type is `outlier_detection`:
  135. [source,console]
  136. --------------------------------------------------
  137. PUT _ml/data_frame/analytics/loganalytics
  138. {
  139. "description": "Outlier detection on log data",
  140. "source": {
  141. "index": "logdata"
  142. },
  143. "dest": {
  144. "index": "logdata_out"
  145. },
  146. "analysis": {
  147. "outlier_detection": {
  148. "compute_feature_influence": true,
  149. "outlier_fraction": 0.05,
  150. "standardization_enabled": true
  151. }
  152. }
  153. }
  154. --------------------------------------------------
  155. // TEST[setup:setup_logdata]
  156. The API returns the following result:
  157. [source,console-result]
  158. ----
  159. {
  160. "id": "loganalytics",
  161. "description": "Outlier detection on log data",
  162. "source": {
  163. "index": ["logdata"],
  164. "query": {
  165. "match_all": {}
  166. }
  167. },
  168. "dest": {
  169. "index": "logdata_out",
  170. "results_field": "ml"
  171. },
  172. "analysis": {
  173. "outlier_detection": {
  174. "compute_feature_influence": true,
  175. "outlier_fraction": 0.05,
  176. "standardization_enabled": true
  177. }
  178. },
  179. "model_memory_limit": "1gb",
  180. "create_time" : 1562265491319,
  181. "version" : "8.0.0",
  182. "allow_lazy_start" : false
  183. }
  184. ----
  185. // TESTRESPONSE[s/1562265491319/$body.$_path/]
  186. // TESTRESPONSE[s/"version": "8.0.0"/"version": $body.version/]
  187. [[ml-put-dfanalytics-example-r]]
  188. ===== {regression-cap} examples
  189. The following example creates the `house_price_regression_analysis`
  190. {dfanalytics-job}, the analysis type is `regression`:
  191. [source,console]
  192. --------------------------------------------------
  193. PUT _ml/data_frame/analytics/house_price_regression_analysis
  194. {
  195. "source": {
  196. "index": "houses_sold_last_10_yrs"
  197. },
  198. "dest": {
  199. "index": "house_price_predictions"
  200. },
  201. "analysis":
  202. {
  203. "regression": {
  204. "dependent_variable": "price"
  205. }
  206. }
  207. }
  208. --------------------------------------------------
  209. // TEST[skip:TBD]
  210. The API returns the following result:
  211. [source,console-result]
  212. ----
  213. {
  214. "id" : "house_price_regression_analysis",
  215. "source" : {
  216. "index" : [
  217. "houses_sold_last_10_yrs"
  218. ],
  219. "query" : {
  220. "match_all" : { }
  221. }
  222. },
  223. "dest" : {
  224. "index" : "house_price_predictions",
  225. "results_field" : "ml"
  226. },
  227. "analysis" : {
  228. "regression" : {
  229. "dependent_variable" : "price",
  230. "training_percent" : 100
  231. }
  232. },
  233. "model_memory_limit" : "1gb",
  234. "create_time" : 1567168659127,
  235. "version" : "8.0.0",
  236. "allow_lazy_start" : false
  237. }
  238. ----
  239. // TESTRESPONSE[s/1567168659127/$body.$_path/]
  240. // TESTRESPONSE[s/"version": "8.0.0"/"version": $body.version/]
  241. The following example creates a job and specifies a training percent:
  242. [source,console]
  243. --------------------------------------------------
  244. PUT _ml/data_frame/analytics/student_performance_mathematics_0.3
  245. {
  246. "source": {
  247. "index": "student_performance_mathematics"
  248. },
  249. "dest": {
  250. "index":"student_performance_mathematics_reg"
  251. },
  252. "analysis":
  253. {
  254. "regression": {
  255. "dependent_variable": "G3",
  256. "training_percent": 70 <1>
  257. }
  258. }
  259. }
  260. --------------------------------------------------
  261. // TEST[skip:TBD]
  262. <1> The `training_percent` defines the percentage of the data set that will be used
  263. for training the model.
  264. [[ml-put-dfanalytics-example-c]]
  265. ===== {classification-cap} example
  266. The following example creates the `loan_classification` {dfanalytics-job}, the
  267. analysis type is `classification`:
  268. [source,console]
  269. --------------------------------------------------
  270. PUT _ml/data_frame/analytics/loan_classification
  271. {
  272. "source" : {
  273. "index": "loan-applicants"
  274. },
  275. "dest" : {
  276. "index": "loan-applicants-classified"
  277. },
  278. "analysis" : {
  279. "classification": {
  280. "dependent_variable": "label",
  281. "training_percent": 75,
  282. "num_top_classes": 2
  283. }
  284. }
  285. }
  286. --------------------------------------------------
  287. // TEST[skip:TBD]