ml-configuring-url.asciidoc 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. [role="xpack"]
  2. [[ml-configuring-url]]
  3. = Adding custom URLs to machine learning results
  4. You can optionally attach one or more custom URLs to your {anomaly-jobs}. These
  5. links appear in the anomalies table in the *Anomaly Explorer* and
  6. *Single Metric Viewer* and can direct you to dashboards, the *Discover* app, or
  7. external websites. For example, you can define a custom URL that provides a way
  8. for users to drill down to the source data from the results set:
  9. [role="screenshot"]
  10. image::images/ml-customurl.jpg["An example of the custom URL links in the Anomaly Explorer anomalies table"]
  11. When you create or edit an {anomaly-job} in {kib}, it simplifies the creation
  12. of the custom URLs for {kib} dashboards and the *Discover* app and it enables
  13. you to test your URLs. For example:
  14. [role="screenshot"]
  15. image::images/ml-customurl-edit.gif["Add a custom URL in {kib}",width=75%]
  16. For each custom URL, you must supply the URL and a label, which is the link text
  17. that appears in the anomalies table. You can also optionally supply a time
  18. range. When you link to *Discover* or a {kib} dashboard, you'll have additional
  19. options for specifying the pertinent index pattern or dashboard name and query
  20. entities.
  21. [discrete]
  22. [[ml-configuring-url-strings]]
  23. == String substitution in custom URLs
  24. You can use dollar sign ($) delimited tokens in a custom URL. These tokens are
  25. substituted for the values of the corresponding fields in the anomaly records.
  26. For example, the `Raw data` URL might resolve to `discover#/?_g=(time:(from:'$earliest$',mode:absolute,to:'$latest$'))&_a=(index:ff959d40-b880-11e8-a6d9-e546fe2bba5f,query:(language:kuery,query:'customer_full_name.keyword:"$customer_full_name.keyword$"'))`. In this case, the pertinent value of the `customer_full_name.keyword` field
  27. is passed to the target page when you click the link.
  28. TIP: Not all fields in your source data exist in the anomaly results. If a
  29. field is specified in the detector as the `field_name`, `by_field_name`,
  30. `over_field_name`, or `partition_field_name`, for example, it can be used in a
  31. custom URL. A field that is used only in the `categorization_field_name`
  32. property, however, does not exist in the anomaly results. When you create your
  33. custom URL in {kib}, the *Query entities* option is shown only when there are
  34. appropriate fields in the detectors.
  35. The `$earliest$` and `$latest$` tokens pass the beginning and end of the time
  36. span of the selected anomaly to the target page. The tokens are substituted with
  37. date-time strings in ISO-8601 format. If you selected an interval of 1 hour for
  38. the anomalies table, these tokens use one hour on either side of the anomaly
  39. time as the earliest and latest times. You can alter this behavior by setting a
  40. time range for the custom URL.
  41. There are also `$mlcategoryregex$` and `$mlcategoryterms$` tokens, which pertain
  42. to {anomaly-jobs} where you are categorizing field values. For more information
  43. about this type of analysis, see <<ml-configuring-categories>>. The
  44. `$mlcategoryregex$` token passes the regular expression value of the category of
  45. the selected anomaly, as identified by the value of the `mlcategory` field of
  46. the anomaly record. The `$mlcategoryterms$` token passes the terms value of the
  47. category of the selected anomaly. Each categorization term is prefixed by a plus
  48. (+) character, so that when the token is passed to a {kib} dashboard, the
  49. resulting dashboard query seeks a match for all of the terms of the category.
  50. For example, the following API updates a job to add a custom URL that uses
  51. `$earliest$`, `$latest$`, and `$mlcategoryterms$` tokens:
  52. [source,console]
  53. ----------------------------------
  54. POST _ml/anomaly_detectors/sample_job/_update
  55. {
  56. "custom_settings": {
  57. "custom_urls": [
  58. {
  59. "url_name": "test-link1",
  60. "time_range": "1h",
  61. "url_value": "discover#/?_g=(time:(from:'$earliest$',mode:quick,to:'$latest$'))&_a=(index:'90943e30-9a47-11e8-b64d-95841ca0b247',query:(language:lucene,query_string:(analyze_wildcard:!t,query:'$mlcategoryterms$')),sort:!(time,desc))"
  62. }
  63. ]
  64. }
  65. }
  66. ----------------------------------
  67. //TEST[skip:setup:sample_job]
  68. When you click this custom URL in the anomalies table in {kib}, it opens up the
  69. *Discover* page and displays source data for the period one hour before and
  70. after the anomaly occurred. Since this job is categorizing log messages, some
  71. `$mlcategoryterms$` token values that are passed to the target page in the query
  72. might include `+REC +Not +INSERTED +TRAN +Table +hostname +dbserver.acme.com`.
  73. [TIP]
  74. ===============================
  75. * The custom URL links in the anomaly tables use pop-ups. You must configure
  76. your web browser so that it does not block pop-up windows or create an exception
  77. for your {kib} URL.
  78. * When creating a link to a {kib} dashboard, the URLs for dashboards can be very
  79. long. Be careful of typos, end of line characters, and URL encoding. Also ensure
  80. you use the appropriate index ID for the target {kib} index pattern.
  81. * If you use an influencer name for string substitution, keep in mind that it
  82. might not always be available in the analysis results and the URL is invalid in
  83. those cases. There is not always a statistically significant influencer for each
  84. anomaly.
  85. * The dates substituted for `$earliest$` and `$latest$` tokens are in
  86. ISO-8601 format and the target system must understand this format.
  87. * If the job performs an analysis against nested JSON fields, the tokens for
  88. string substitution can refer to these fields using dot notation. For example,
  89. `$cpu.total$`.
  90. * {es} source data mappings might make it difficult for the query string to work.
  91. Test the custom URL before saving the job configuration to check that it works
  92. as expected, particularly when using string substitution.
  93. ===============================