put-dfanalytics.asciidoc 11 KB

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