user-agent.asciidoc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. [[user-agent-processor]]
  2. === User agent processor
  3. ++++
  4. <titleabbrev>User agent</titleabbrev>
  5. ++++
  6. The `user_agent` processor extracts details from the user agent string a browser sends with its web requests.
  7. This processor adds this information by default under the `user_agent` field.
  8. The ingest-user-agent module ships by default with the regexes.yaml made available by uap-java with an Apache 2.0 license. For more details see https://github.com/ua-parser/uap-core.
  9. [[using-ingest-user-agent]]
  10. ==== Using the user_agent Processor in a Pipeline
  11. [[ingest-user-agent-options]]
  12. .User-agent options
  13. [options="header"]
  14. |======
  15. | Name | Required | Default | Description
  16. | `field` | yes | - | The field containing the user agent string.
  17. | `target_field` | no | user_agent | The field that will be filled with the user agent details.
  18. | `regex_file` | no | - | The name of the file in the `config/ingest-user-agent` directory containing the regular expressions for parsing the user agent string. Both the directory and the file have to be created before starting Elasticsearch. If not specified, ingest-user-agent will use the regexes.yaml from uap-core it ships with (see below).
  19. | `properties` | no | [`name`, `major`, `minor`, `patch`, `build`, `os`, `os_name`, `os_major`, `os_minor`, `device`] | Controls what properties are added to `target_field`.
  20. | `extract_device_type` | no | `false` | beta:[] Extracts device type from the user agent string on a best-effort basis.
  21. | `ignore_missing` | no | `false` | If `true` and `field` does not exist, the processor quietly exits without modifying the document
  22. |======
  23. Here is an example that adds the user agent details to the `user_agent` field based on the `agent` field:
  24. [source,console]
  25. --------------------------------------------------
  26. PUT _ingest/pipeline/user_agent
  27. {
  28. "description" : "Add user agent information",
  29. "processors" : [
  30. {
  31. "user_agent" : {
  32. "field" : "agent"
  33. }
  34. }
  35. ]
  36. }
  37. PUT my-index-000001/_doc/my_id?pipeline=user_agent
  38. {
  39. "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"
  40. }
  41. GET my-index-000001/_doc/my_id
  42. --------------------------------------------------
  43. Which returns
  44. [source,console-result]
  45. --------------------------------------------------
  46. {
  47. "found": true,
  48. "_index": "my-index-000001",
  49. "_id": "my_id",
  50. "_version": 1,
  51. "_seq_no": 22,
  52. "_primary_term": 1,
  53. "_source": {
  54. "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
  55. "user_agent": {
  56. "name": "Chrome",
  57. "original": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
  58. "version": "51.0.2704.103",
  59. "os": {
  60. "name": "Mac OS X",
  61. "version": "10.10.5",
  62. "full": "Mac OS X 10.10.5"
  63. },
  64. "device" : {
  65. "name" : "Mac"
  66. },
  67. }
  68. }
  69. }
  70. --------------------------------------------------
  71. // TESTRESPONSE[s/"_seq_no": \d+/"_seq_no" : $body._seq_no/ s/"_primary_term": 1/"_primary_term" : $body._primary_term/]
  72. ===== Using a custom regex file
  73. To use a custom regex file for parsing the user agents, that file has to be put into the `config/ingest-user-agent` directory and
  74. has to have a `.yml` filename extension. The file has to be present at node startup, any changes to it or any new files added
  75. while the node is running will not have any effect.
  76. In practice, it will make most sense for any custom regex file to be a variant of the default file, either a more recent version
  77. or a customised version.
  78. The default file included in `ingest-user-agent` is the `regexes.yaml` from uap-core: https://github.com/ua-parser/uap-core/blob/master/regexes.yaml
  79. [[ingest-user-agent-settings]]
  80. ===== Node Settings
  81. The `user_agent` processor supports the following setting:
  82. `ingest.user_agent.cache_size`::
  83. The maximum number of results that should be cached. Defaults to `1000`.
  84. Note that these settings are node settings and apply to all `user_agent` processors, i.e. there is one cache for all defined `user_agent` processors.