| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 | [role="xpack"][testenv="platinum"][[ml-get-category]]= Get categories API++++<titleabbrev>Get categories</titleabbrev>++++Retrieves {anomaly-job} results for one or more categories.[[ml-get-category-request]]== {api-request-title}`GET _ml/anomaly_detectors/<job_id>/results/categories` +`GET _ml/anomaly_detectors/<job_id>/results/categories/<category_id>`[[ml-get-category-prereqs]]== {api-prereq-title}Requires the `monitor_ml` cluster privilege. This privilege is included in the `machine_learning_user` built-in role.[[ml-get-category-desc]]== {api-description-title}When `categorization_field_name` is specified in the job configuration, it ispossible to view the definitions of the resulting categories. A categorydefinition describes the common terms matched and contains examples of matchedvalues.The anomaly results from a categorization analysis are available as bucket,influencer, and record results. For example, the results might indicate thatat 16:45 there was an unusual count of log message category 11. You can thenexamine the description and examples of that category. For more information, see{ml-docs}/ml-configuring-categories.html[Categorizing log messages].[[ml-get-category-path-parms]]== {api-path-parms-title}`<job_id>`::(Required, string)include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=job-id-anomaly-detection]`<category_id>`::(Optional, long) Identifier for the category, which is unique in the job. If youspecify neither the category ID nor the `partition_field_value`, the API returnsinformation about all categories. If you specify only the`partition_field_value`, it returns information about all categories for thespecified partition.[[ml-get-category-request-body]]== {api-request-body-title}`page`.`from`::(Optional, integer) Skips the specified number of categories. Defaults to `0`.`page`.`size`::(Optional, integer) Specifies the maximum number of categories to obtain. Defaults to `100`.`partition_field_value`::(Optional, string) Only return categories for the specified partition.[[ml-get-category-results]]== {api-response-body-title}The API returns an array of category objects, which have the following properties:`category_id`::(unsigned integer) A unique identifier for the category. `category_id` is uniqueat the job level, even when per-partition categorization is enabled.`examples`::(array) A list of examples of actual values that matched the category.`grok_pattern`::experimental[] (string) A Grok pattern that could be used in {ls} or an ingest pipeline to extract fields from messages that match the category. This field isexperimental and may be changed or removed in a future release. The Grokpatterns that are found are not optimal, but are often a good starting point formanual tweaking.`job_id`::(string)include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=job-id-anomaly-detection]`max_matching_length`::(unsigned integer) The maximum length of the fields that matched the category.The value is increased by 10% to enable matching for similar fields that havenot been analyzed.// This doesn't use the shared description because there are// categorization-specific aspects to its use in this context`partition_field_name`::(string) If per-partition categorization is enabled, this property identifiesthe field used to segment the categorization. It is not present whenper-partition categorization is disabled.`partition_field_value`::(string) If per-partition categorization is enabled, this property identifiesthe value of the `partition_field_name` for the category. It is not present whenper-partition categorization is disabled.`regex`::(string) A regular expression that is used to search for values that match thecategory.`terms`::(string) A space separated list of the common tokens that are matched in valuesof the category.`num_matches`::(long) The number of messages that have been matched by this category. This isonly guaranteed to have the latest accurate count after a job `_flush` or `_close``preferred_to_categories`::(list) A list of `category_id` entries that this current category encompasses.Any new message that is processed by the categorizer will match against thiscategory and not any of the categories in this list. This is only guaranteedto have the latest accurate list of categories after a job `_flush` or `_close`[[ml-get-category-example]]== {api-examples-title}[source,console]--------------------------------------------------GET _ml/anomaly_detectors/esxi_log/results/categories{  "page":{    "size": 1  }}--------------------------------------------------// TEST[skip:todo][source,js]----{  "count": 11,  "categories": [    {      "job_id" : "esxi_log",      "category_id" : 1,      "terms" : "Vpxa verbose vpxavpxaInvtVm opID VpxaInvtVmChangeListener Guest DiskInfo Changed",      "regex" : ".*?Vpxa.+?verbose.+?vpxavpxaInvtVm.+?opID.+?VpxaInvtVmChangeListener.+?Guest.+?DiskInfo.+?Changed.*",      "max_matching_length": 154,      "examples" : [        "Oct 19 17:04:44 esxi1.acme.com Vpxa: [3CB3FB90 verbose 'vpxavpxaInvtVm' opID=WFU-33d82c31] [VpxaInvtVmChangeListener] Guest DiskInfo Changed",        "Oct 19 17:04:45 esxi2.acme.com Vpxa: [3CA66B90 verbose 'vpxavpxaInvtVm' opID=WFU-33927856] [VpxaInvtVmChangeListener] Guest DiskInfo Changed",        "Oct 19 17:04:51 esxi1.acme.com Vpxa: [FFDBAB90 verbose 'vpxavpxaInvtVm' opID=WFU-25e0d447] [VpxaInvtVmChangeListener] Guest DiskInfo Changed",        "Oct 19 17:04:58 esxi2.acme.com Vpxa: [FFDDBB90 verbose 'vpxavpxaInvtVm' opID=WFU-bbff0134] [VpxaInvtVmChangeListener] Guest DiskInfo Changed"      ],      "grok_pattern" : ".*?%{SYSLOGTIMESTAMP:timestamp}.+?Vpxa.+?%{BASE16NUM:field}.+?verbose.+?vpxavpxaInvtVm.+?opID.+?VpxaInvtVmChangeListener.+?Guest.+?DiskInfo.+?Changed.*"    }  ]}----
 |