-
Notifications
You must be signed in to change notification settings - Fork 25.8k
ES|QL: Adding USER_AGENT command
#144384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
ES|QL: Adding USER_AGENT command
#144384
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
8c28e2d
ES|QL: Adding command
eyalkoren 9cb644d
Merge remote-tracking branch 'upstream/main' into esql-user_agent-com…
eyalkoren 75f6e33
Update docs/changelog/144384.yaml
eyalkoren 0e81635
Remove wrong gradle change
eyalkoren 54adbd1
Fixing indentation in Expression.g4
eyalkoren 7f888e0
Merge remote-tracking branch 'eyalkoren/esql-user_agent-command' into…
eyalkoren f727f6f
Updating changelog name
eyalkoren 345fae0
Adding Guice binding for UserAgentParserRegistry
eyalkoren 80cdda2
Merge remote-tracking branch 'upstream/main' into esql-user_agent-com…
eyalkoren 5e3c5b1
Remove redundant Guice binding
eyalkoren 7589858
Merge remote-tracking branch 'upstream/main' into esql-user_agent-com…
eyalkoren 2379cae
Add special handling in EsqlNodeSubclassTests
eyalkoren 9c9462e
Merge remote-tracking branch 'upstream/main' into esql-user_agent-com…
eyalkoren 8cab787
Complete merge
eyalkoren 261dc70
[CI] Auto commit changes from spotless
97b0f42
Fixing comment in auto-generated docs example
eyalkoren ebad698
Merge remote-tracking branch 'upstream/main' into esql-user_agent-com…
eyalkoren 3598bc4
Merge remote-tracking branch 'upstream/main' into esql-user_agent-com…
eyalkoren a5ab808
Regenerated lexer files
eyalkoren 05d150d
Fix CsvIT
eyalkoren a7fc46b
Merge remote-tracking branch 'upstream/main' into esql-user_agent-com…
eyalkoren cacc7d5
Extend tests and fix docs
eyalkoren fe282b9
Merge remote-tracking branch 'upstream/main' into esql-user_agent-com…
eyalkoren 0cbf63b
Completing merge and adding tests
eyalkoren ba1d1cb
Spotless
eyalkoren 042ce4e
Merge remote-tracking branch 'upstream/main' into esql-user_agent-com…
eyalkoren 7ae79ab
Merge remote-tracking branch 'upstream/main' into esql-user_agent-com…
eyalkoren dc1bb0e
Applying review comment and adjusting to test API change
eyalkoren b6e768a
Merge remote-tracking branch 'upstream/main' into esql-user_agent-com…
eyalkoren ccaf648
Some minor fixes
eyalkoren 25aab3d
Merge remote-tracking branch 'upstream/main' into esql-user_agent-com…
eyalkoren fbf2ab7
Merge remote-tracking branch 'upstream/main' into esql-user_agent-com…
eyalkoren a2b2f43
Merge remote-tracking branch 'upstream/main' into esql-user_agent-com…
eyalkoren 67a7d66
[CI] Auto commit changes from spotless
7c8a90f
Merge remote-tracking branch 'upstream/main' into esql-user_agent-com…
eyalkoren a1efaa4
Complete merge
eyalkoren a63846e
Merge remote-tracking branch 'eyalkoren/esql-user_agent-command' into…
eyalkoren e7ff9fe
Merge remote-tracking branch 'upstream/main' into esql-user_agent-com…
eyalkoren 7b0a2a8
finish merge
eyalkoren aceb219
Applying review commands - part 1
eyalkoren b31c430
Replace scattered optimization tests with Golden Tests
eyalkoren e9e917b
Applying review commands - part 3
eyalkoren c8c7a90
Fixing Golden Tests with new info() output
eyalkoren b28b69d
Merge remote-tracking branch 'upstream/main' into esql-user_agent-com…
eyalkoren 69bf803
Merge branch 'main' into esql-user_agent-command
eyalkoren dcdb9a7
Merge branch 'main' into esql-user_agent-command
eyalkoren c035fcb
Merge remote-tracking branch 'upstream/main' into esql-user_agent-com…
eyalkoren 8d15c56
Finish merge
eyalkoren a0d7856
[CI] Auto commit changes from spotless
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| area: ES|QL | ||
| issues: | ||
| - 134886 | ||
| pr: 144384 | ||
| summary: Adding ES|QL USER_AGENT command | ||
| type: feature |
11 changes: 11 additions & 0 deletions
11
...e/query-languages/esql/_snippets/commands/examples/user_agent.csv-spec/basic.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| % This is generated by ESQL's CommandDocsTests. Do not edit it. See ../README.md for how to regenerate it. | ||
|
|
||
| ```esql | ||
| ROW input = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.149 Safari/537.36" | ||
| | USER_AGENT ua = input WITH { "extract_device_type": true } | ||
| | KEEP ua.* | ||
| ``` | ||
|
|
||
| | ua.name:keyword | ua.version:keyword | ua.os.name:keyword | ua.os.version:keyword | ua.os.full:keyword | ua.device.name:keyword | ua.device.type:keyword | | ||
| | --- | --- | --- | --- | --- | --- | --- | | ||
| | Chrome | 33.0.1750.149 | Mac OS X | 10.9.2 | Mac OS X 10.9.2 | Mac | Desktop | |
117 changes: 117 additions & 0 deletions
117
docs/reference/query-languages/esql/_snippets/commands/layout/user_agent.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| ```yaml {applies_to} | ||
| serverless: preview | ||
| stack: preview 9.4 | ||
| ``` | ||
|
|
||
| The `USER_AGENT` processing command parses a user-agent string and extracts its components (name, version, OS, device) into new columns. | ||
|
|
||
| ::::{note} | ||
| This command doesn't support multi-value inputs. | ||
| :::: | ||
|
|
||
|
|
||
| ## Syntax | ||
|
|
||
| ```esql | ||
| USER_AGENT prefix = expression [WITH { option = value [, ...] }] | ||
| ``` | ||
|
|
||
| ## Parameters | ||
|
|
||
| `prefix` | ||
| : The prefix for the output columns. The extracted components are available as `prefix.component`. | ||
|
|
||
| `expression` | ||
| : The string expression containing the user-agent string to parse. | ||
|
|
||
| ## WITH options | ||
|
|
||
| `regex_file` | ||
| : The name of the parser configuration to use. Default: `_default_`, which uses the built-in regexes from [uap-core](https://github.com/ua-parser/uap-core). To use a custom regex file, place a `.yml` file in the `config/user-agent` directory on each node before starting Elasticsearch. The file must be present at node startup; changes or new files added while the node is running have no effect. Pass the filename (including the `.yml` extension) as the value. Custom regex files are typically variants of the default, either a more recent uap-core release or a customized version. | ||
|
|
||
| `extract_device_type` | ||
| : When `true`, extracts device type (e.g., Desktop, Phone, Tablet) on a best-effort basis and includes `prefix.device.type` in the output. Default: `false`. | ||
|
|
||
| `properties` | ||
| : List of property groups to include in the output. Each value expands to one or more columns: `name` → `prefix.name`; `version` → `prefix.version`; `os` → `prefix.os.name`, `prefix.os.version`, `prefix.os.full`; `device` → `prefix.device.name` (and `prefix.device.type` when `extract_device_type` is `true`). Default: `["name", "version", "os", "device"]`. You can pass a subset to reduce output columns. | ||
|
|
||
| ## Using a custom regex file | ||
|
|
||
| To use a custom regex file instead of the built-in uap-core patterns: | ||
|
|
||
| 1. Place a `.yml` file in the `config/user-agent` directory on each node. | ||
| 2. Create the directory and file before starting Elasticsearch. | ||
| 3. Pass the filename (including the `.yml` extension) as the `regex_file` option. | ||
|
|
||
| Files must be present at node startup. Changes to existing files or new files added while the node is running have no effect until the node is restarted. | ||
|
|
||
| ::::{note} | ||
| Before version 9.4, this directory was named `config/ingest-user-agent`. The old directory name is still supported as a fallback but is deprecated. | ||
| :::: | ||
|
|
||
| Custom regex files are typically variants of the default [uap-core regexes.yaml](https://github.com/ua-parser/uap-core/blob/master/regexes.yaml), either a more recent release or a customized version for specific user-agent patterns. Use a custom file when you need to support newer user-agent formats before they are available in the built-in patterns, or to parse specialized or non-standard user-agent strings. | ||
|
|
||
| ## Description | ||
|
|
||
| The `USER_AGENT` command parses a user-agent string and extracts its parts into new columns. | ||
| The new columns are prefixed with the specified `prefix` followed by a dot (`.`). | ||
|
|
||
| This command is the query-time equivalent of the [User-Agent ingest processor](/reference/enrich-processor/user-agent-processor.md). | ||
|
|
||
| The following columns may be created (depending on `properties` and `extract_device_type`): | ||
|
|
||
| `prefix.name` | ||
| : The user-agent name (e.g., Chrome, Firefox). | ||
|
|
||
| `prefix.version` | ||
| : The user-agent version. | ||
|
|
||
| `prefix.os.name` | ||
| : The operating system name. | ||
|
|
||
| `prefix.os.version` | ||
| : The operating system version. | ||
|
|
||
| `prefix.os.full` | ||
| : The full operating system string. | ||
|
|
||
| `prefix.device.name` | ||
| : The device name. | ||
|
|
||
| `prefix.device.type` | ||
| : The device type (e.g., Desktop, Phone). Only present when `extract_device_type` is `true`. | ||
|
|
||
| If a component is missing or the input is not a valid user-agent string, the corresponding column contains `null`. | ||
| If the expression evaluates to `null` or blank, all output columns are `null`. | ||
|
|
||
| ## Examples | ||
|
|
||
| The following example parses a user-agent string and extracts its parts: | ||
|
|
||
| :::{include} ../examples/user_agent.csv-spec/basic.md | ||
| ::: | ||
|
|
||
| To limit output to specific properties or include device type, use the `properties` and `extract_device_type` options: | ||
|
|
||
| ```esql | ||
| ROW ua_str = "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15" | ||
| | USER_AGENT ua = ua_str WITH { "properties": ["name", "version", "device"], "extract_device_type": true } | ||
| | KEEP ua.* | ||
| ``` | ||
|
|
||
| To use a custom regex file (e.g. `my-regexes.yml` in `config/user-agent`), pass the filename including the extension: | ||
|
|
||
| ```esql | ||
| FROM web_logs | ||
| | USER_AGENT ua = user_agent WITH { "regex_file": "my-regexes.yml" } | ||
| | KEEP ua.name, ua.version | ||
| ``` | ||
|
|
||
| You can use the extracted parts in subsequent commands, for example to filter by browser: | ||
|
|
||
| ```esql | ||
| FROM web_logs | ||
| | USER_AGENT ua = user_agent | ||
| | WHERE ua.name == "Firefox" | ||
| | STATS COUNT(*) BY ua.version | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
docs/reference/query-languages/esql/commands/user-agent.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| navigation_title: "USER_AGENT" | ||
| mapped_pages: | ||
| - https://www.elastic.co/guide/en/elasticsearch/reference/current/esql-commands.html#esql-user_agent | ||
| --- | ||
|
|
||
| # {{esql}} `USER_AGENT` command [esql-user_agent] | ||
|
|
||
| :::{include} ../_snippets/commands/layout/user_agent.md | ||
| ::: |
5 changes: 5 additions & 0 deletions
5
docs/reference/query-languages/esql/kibana/definition/commands/user_agent.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.