geo.asciidoc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. [role="xpack"]
  2. [[ml-geo-functions]]
  3. === Geographic functions
  4. The geographic functions detect anomalies in the geographic location of the
  5. input data.
  6. The {xpackml} features include the following geographic function: `lat_long`.
  7. NOTE: You cannot create forecasts for jobs that contain geographic functions.
  8. You also cannot add rules with conditions to detectors that use geographic
  9. functions.
  10. [float]
  11. [[ml-lat-long]]
  12. ==== Lat_long
  13. The `lat_long` function detects anomalies in the geographic location of the
  14. input data.
  15. This function supports the following properties:
  16. * `field_name` (required)
  17. * `by_field_name` (optional)
  18. * `over_field_name` (optional)
  19. * `partition_field_name` (optional)
  20. For more information about those properties,
  21. see {ref}/ml-job-resource.html#ml-detectorconfig[Detector Configuration Objects].
  22. .Example 1: Analyzing transactions with the lat_long function
  23. [source,js]
  24. --------------------------------------------------
  25. PUT _xpack/ml/anomaly_detectors/example1
  26. {
  27. "analysis_config": {
  28. "detectors": [{
  29. "function" : "lat_long",
  30. "field_name" : "transactionCoordinates",
  31. "by_field_name" : "creditCardNumber"
  32. }]
  33. },
  34. "data_description": {
  35. "time_field":"timestamp",
  36. "time_format": "epoch_ms"
  37. }
  38. }
  39. --------------------------------------------------
  40. // CONSOLE
  41. // TEST[skip:needs-licence]
  42. If you use this `lat_long` function in a detector in your job, it
  43. detects anomalies where the geographic location of a credit card transaction is
  44. unusual for a particular customer’s credit card. An anomaly might indicate fraud.
  45. IMPORTANT: The `field_name` that you supply must be a single string that contains
  46. two comma-separated numbers of the form `latitude,longitude`. The `latitude` and
  47. `longitude` must be in the range -180 to 180 and represent a point on the
  48. surface of the Earth.
  49. For example, JSON data might contain the following transaction coordinates:
  50. [source,js]
  51. --------------------------------------------------
  52. {
  53. "time": 1460464275,
  54. "transactionCoordinates": "40.7,-74.0",
  55. "creditCardNumber": "1234123412341234"
  56. }
  57. --------------------------------------------------
  58. // NOTCONSOLE
  59. In {es}, location data is likely to be stored in `geo_point` fields. For more
  60. information, see {ref}/geo-point.html[Geo-point datatype]. This data type is not
  61. supported natively in {xpackml} features. You can, however, use Painless scripts
  62. in `script_fields` in your {dfeed} to transform the data into an appropriate
  63. format. For example, the following Painless script transforms
  64. `"coords": {"lat" : 41.44, "lon":90.5}` into `"lat-lon": "41.44,90.5"`:
  65. [source,js]
  66. --------------------------------------------------
  67. PUT _xpack/ml/datafeeds/datafeed-test2
  68. {
  69. "job_id": "farequote",
  70. "indices": ["farequote"],
  71. "query": {
  72. "match_all": {
  73. "boost": 1
  74. }
  75. },
  76. "script_fields": {
  77. "lat-lon": {
  78. "script": {
  79. "source": "doc['coords'].lat + ',' + doc['coords'].lon",
  80. "lang": "painless"
  81. }
  82. }
  83. }
  84. }
  85. --------------------------------------------------
  86. // CONSOLE
  87. // TEST[skip:setup:farequote_job]
  88. For more information, see <<ml-configuring-transform>>.