2016-07-05 03:42:29 -04:00
[[ingest-user-agent]]
=== Ingest user agent processor plugin
2016-07-01 09:49:43 -04:00
2016-07-05 03:42:29 -04:00
The `user_agent` processor extracts details from the user agent string a browser sends with its web requests.
This processor adds this information by default under the `user_agent` field.
2016-07-01 09:49:43 -04:00
2016-07-05 03:42:29 -04:00
The ingest-user-agent plugin 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.
2016-07-01 09:49:43 -04:00
2017-04-20 09:01:37 -04:00
:plugin_name: ingest-user-agent
include::install_remove.asciidoc[]
2016-07-01 09:49:43 -04:00
2016-07-05 03:42:29 -04:00
[[using-ingest-user-agent]]
==== Using the user_agent Processor in a Pipeline
2016-07-01 09:49:43 -04:00
2016-07-05 03:42:29 -04:00
[[ingest-user-agent-options]]
.User-agent options
2016-07-01 09:49:43 -04:00
[options="header"]
|======
2016-12-20 13:53:28 -05:00
| Name | Required | Default | Description
| `field` | yes | - | The field containing the user agent string.
| `target_field` | no | user_agent | The field that will be filled with the user agent details.
| `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).
2016-07-01 09:49:43 -04:00
| `properties` | no | [`name`, `major`, `minor`, `patch`, `build`, `os`, `os_name`, `os_major`, `os_minor`, `device`] | Controls what properties are added to `target_field`.
2016-12-20 13:53:28 -05:00
| `ignore_missing` | no | `false` | If `true` and `field` does not exist, the processor quietly exits without modifying the document
2016-07-01 09:49:43 -04:00
|======
2016-07-05 03:42:29 -04:00
Here is an example that adds the user agent details to the `user_agent` field based on the `agent` field:
2016-07-01 09:49:43 -04:00
[source,js]
--------------------------------------------------
2016-08-10 11:12:41 -04:00
PUT _ingest/pipeline/user_agent
2016-07-01 09:49:43 -04:00
{
2016-08-10 11:12:41 -04:00
"description" : "Add user agent information",
2016-07-01 09:49:43 -04:00
"processors" : [
{
2016-07-05 03:42:29 -04:00
"user_agent" : {
2016-07-01 09:49:43 -04:00
"field" : "agent"
}
}
]
}
2018-10-22 14:54:04 -04:00
PUT my_index/_doc/my_id?pipeline=user_agent
2016-08-10 11:12:41 -04:00
{
"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"
}
2018-10-22 14:54:04 -04:00
GET my_index/_doc/my_id
2016-08-10 11:12:41 -04:00
--------------------------------------------------
// CONSOLE
Which returns
[source,js]
--------------------------------------------------
{
"found": true,
"_index": "my_index",
2018-10-22 14:54:04 -04:00
"_type": "_doc",
2016-08-10 11:12:41 -04:00
"_id": "my_id",
"_version": 1,
2018-12-17 09:22:13 -05:00
"_seq_no": 22,
"_primary_term": 1,
2016-08-10 11:12:41 -04:00
"_source": {
"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",
"user_agent": {
"name": "Chrome",
"major": "51",
"minor": "0",
"patch": "2704",
"os_name": "Mac OS X",
"os": "Mac OS X 10.10.5",
"os_major": "10",
"os_minor": "10",
"device": "Other"
}
}
}
2016-07-01 09:49:43 -04:00
--------------------------------------------------
2018-12-17 09:22:13 -05:00
// TESTRESPONSE[s/"_seq_no": \d+/"_seq_no" : $body._seq_no/ s/"_primary_term": 1/"_primary_term" : $body._primary_term/]
2016-07-01 09:49:43 -04:00
===== Using a custom regex file
2016-07-05 03:42:29 -04:00
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
2016-07-01 09:49:43 -04:00
has to have a `.yaml` filename extension. The file has to be present at node startup, any changes to it or any new files added
while the node is running will not have any effect.
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
or a customised version.
2016-07-05 03:42:29 -04:00
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