-
Notifications
You must be signed in to change notification settings - Fork 210
Query Analytics logging docs #5039
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
base: main
Are you sure you want to change the base?
Changes from all commits
f0ffd20
04cc9ca
868c92d
92b4175
671a9c2
64cb6fb
5cb9c8f
b16727f
08336d9
7053615
c6c5d61
4cb83f0
d8214b3
d032546
c4e831b
8e0a5b2
0f8ce24
1f14441
80f091c
934f1b7
f548112
5f5aa4a
dd90dc2
ac18736
f4e8474
36da612
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| --- | ||
|
|
||
| applies_to: | ||
| deployment: | ||
| self: ga 9.4 | ||
|
|
||
| --- | ||
|
|
||
| # Query logging [logging] | ||
|
|
||
| {{es}} allows to log every querying operation performed on the cluster. This supports endpoints like `_search`, `_msearch`, [{{esql}}](/explore-analyze/discover/try-esql.md), [SQL](elasticsearch://reference/query-languages/sql/sql-rest-format.md#_csv), [EQL](elasticsearch://reference/query-languages/eql/eql-syntax.md) and other APIs that search or query {{es}} indices. | ||
|
|
||
| The following query types are supported: | ||
|
|
||
| - `dsl`: Logs every search operation performed on using the [Query DSL](/explore-analyze/query-filter/languages/querydsl.md). | ||
| - `esql`: Logs every query operation performed on the cluster using [{{esql}}](/explore-analyze/query-filter/languages/esql-kibana.md). | ||
| - `eql`: Logs every query operation performed on the cluster using [EQL](/explore-analyze/query-filter/languages/eql.md). | ||
| - `sql`: Logs every query operation performed on the cluster using [SQL](/explore-analyze/query-filter/languages/sql.md). | ||
|
|
||
| By default, the logging is turned off. To enable the logging, set the `elasticsearch.activitylog.enabled` property to `true` in the `elasticsearch.yml` configuration file or using the [settings API]({{es-apis}}operation/operation-cluster-put-settings): | ||
|
|
||
| ```yaml | ||
| elasticsearch.activitylog.enabled: true | ||
| ``` | ||
|
|
||
| By default, search (`dsl`) queries that query only system indices are not logged. To enable logging of such queries, use the `elasticsearch.activitylog.search.include.system_indices` setting described below. | ||
|
|
||
| ## Configuring query logging | ||
|
|
||
| The following configuration options are available: | ||
|
|
||
| - `elasticsearch.activitylog.enabled`: Enables or disables query logging. The default is `false` (disabled). | ||
|
Check notice on line 32 in deploy-manage/monitor/logging-configuration/query-logs.md
|
||
| - `elasticsearch.activitylog.threshold`: Sets the request duration threshold for logging events. If the threshold is set to the value greater than 0, only the requests that take as much time (in milliseconds) or longer than the threshold are logged. The default is 0 (no threshold). | ||
| - `elasticsearch.activitylog.include.user`: Enables or disables the user information logging. The default is `true` (enabled by default). | ||
|
Check notice on line 34 in deploy-manage/monitor/logging-configuration/query-logs.md
|
||
| - `elasticsearch.activitylog.search.include.system_indices`: Enables or disables logging of queries performed on system indices for the dsl search module. The default is not logging system indices. | ||
|
Check notice on line 35 in deploy-manage/monitor/logging-configuration/query-logs.md
|
||
|
|
||
| ## What is included in the log | ||
|
|
||
| The logs are output in JSON format, and include the following fields: | ||
|
|
||
| - `@timestamp`: The timestamp of the log entry. | ||
| - `event.outcome`: Whether the request was successful (`success`) or not (`failure`). | ||
| - `event.duration`: How long (in nanoseconds) the request took to complete. | ||
| - `error.type` and `error.message`: Error information fields if the request failed. | ||
| - `user.*`: User information fields if enabled. | ||
| - `http.request.headers.x_opaque_id`: The X-Opaque-Id header value if enabled. See [X-Opaque-Id HTTP header](elasticsearch://reference/elasticsearch/rest-apis/api-conventions.md#x-opaque-id) for details and best practices. | ||
| - `trace.id`: [Trace ID](ecs://reference/ecs-tracing.md#field-trace-id) information. | ||
smalyshev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ### Query logging specific fields | ||
|
|
||
| - `elasticsearch.querylog.type`: The type of operation (`dsl`, `esql`, `sql`, `eql`). | ||
| - `elasticsearch.querylog.took`: How long (in nanoseconds) the request took to complete. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how does this relate to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the same thing |
||
| - `elasticsearch.querylog.took_millis`: How long (in milliseconds) the request took to complete. | ||
| - `elasticsearch.querylog.timed_out`: Boolean specifying whether the query timed out. | ||
| - `elasticsearch.querylog.query`: The query text (depending on the query language, could be string or JSON). | ||
| - `elasticsearch.querylog.indices`: Array containing the indices that were requested. These may not be fully resolved. May contain wildcards and index expressions, and it is not guaranteed these resolve to any specific index or exist at all. Note that for some queries (like {{esql}}) indices are part of the query text and may not be available as a separate field. | ||
|
Check notice on line 56 in deploy-manage/monitor/logging-configuration/query-logs.md
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
what does this mean?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indices field is now empty for ESQL, since indices are only in the query text. I have some ideas on how it's possible to extract the index information, but right now we don't have it. |
||
| - `elasticsearch.querylog.result_count`: The number of results actually returned in the response. | ||
| - `elasticsearch.querylog.is_system`: If system index logging is enabled, indicates whether the request was performed only on system indices. | ||
| - `elasticsearch.querylog.has_aggregations`: For a `dsl` search result, this boolean flag specifies whether the result has a non-empty aggregations section. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this be move to the "DSL Search specific fields" section?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not under |
||
| - `elasticsearch.querylog.shards.successful`, `elasticsearch.querylog.shards.skipped`, `elasticsearch.querylog.shards.failed`: How many shards were successful, skipped and failed during the query execution. | ||
| - `elasticsearch.querylog.is_ccs` - Indicates whether the request was a [{{ccs}}](/explore-analyze/cross-cluster-search.md). | ||
| - `elasticsearch.querylog.remote_count` - For cross-cluster queries, this field indicates the number of remote clusters involved in the query execution. | ||
| - `elasticsearch.querylog.is_remote` - For `dsl` queries, indicates whether the query was initiated by a remote cluster. | ||
|
|
||
| Additional fields specific to {{es}} environment may be added. | ||
|
|
||
| In addition to the fields listed above, each query language may include fields specific to it, prefixed with `elasticsearch.querylog.` | ||
|
|
||
| ### DSL Search specific fields | ||
|
|
||
| - `search.total_count`: The “total hits” value, as reported by [the search response](/solutions/search/the-search-api.md). | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so this is
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same goes for the other language-specific fields
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, you want to put the full name there every time? |
||
| - `search.total_count_partial`: Set to `true` in case the total count does not reflect the full number of matches for some reason (like [`track_total_hits` limitation](/solutions/search/the-search-api.md#track-total-hits)). | ||
|
|
||
| ### {{esql}} | ||
|
|
||
| - `esql.profile.*.took`: {{esql}} query profiling metrics, in nanoseconds | ||
|
|
||
| ### Example log entry | ||
|
|
||
| ```json | ||
| { | ||
| "@timestamp": "2026-03-04T19:40:34.736Z", | ||
| "log.level": "INFO", | ||
| "auth.type": "REALM", | ||
| "elasticsearch.querylog.indices": [ | ||
| "query_log_test_index" | ||
| ], | ||
| "elasticsearch.querylog.query": "{\"size\":10,\"query\":{\"match_all\":{\"boost\":1.0}}}", | ||
| "elasticsearch.querylog.result_count": 3, | ||
| "elasticsearch.querylog.search.total_count": 3, | ||
| "elasticsearch.querylog.shards.successful": 1, | ||
| "elasticsearch.querylog.took": 1985208, | ||
| "elasticsearch.querylog.took_millis": 1, | ||
| "elasticsearch.querylog.type": "dsl", | ||
| "elasticsearch.task.id": 29848, | ||
| "event.duration": 1985208, | ||
| "event.outcome": "success", | ||
| "http.request.headers.x_opaque_id": "opaque-1773275310", | ||
| "trace.id": "0af7651916cd43dd8448eb211c80319c", | ||
| "user.name": "elastic", | ||
| "user.realm": "reserved", | ||
| "ecs.version": "1.2.0", | ||
| "service.name": "ES_ECS", | ||
| "event.dataset": "elasticsearch.querylog", | ||
| "process.thread.name": "elasticsearch[node-1][search][T#14]", | ||
| "log.logger": "elasticsearch.querylog", | ||
| "elasticsearch.cluster.uuid": "gjYgb-uQQAuLmDoKlQInZw", | ||
| "elasticsearch.node.id": "juurGSfgRYGwTP2ttZbtOQ", | ||
| "elasticsearch.node.name": "node-1", | ||
| "elasticsearch.cluster.name": "querying" | ||
| } | ||
| ``` | ||
|
|
||
| Example failure entry: | ||
|
|
||
| ```json | ||
| { | ||
| "@timestamp": "2026-03-04T19:40:35.271Z", | ||
| "log.level": "INFO", | ||
| "auth.type": "REALM", | ||
| "elasticsearch.querylog.indices": [ | ||
| "nonexistent_index_xyz" | ||
| ], | ||
| "elasticsearch.querylog.query": "any where true", | ||
| "elasticsearch.querylog.result_count": 0, | ||
| "elasticsearch.querylog.took": 1326334, | ||
| "elasticsearch.querylog.took_millis": 1, | ||
| "elasticsearch.querylog.type": "eql", | ||
| "error.message": "no such index [Unknown index [nonexistent_index_xyz]]", | ||
| "error.type": "org.elasticsearch.index.IndexNotFoundException", | ||
| "event.duration": 1326334, | ||
| "event.outcome": "failure", | ||
| "http.request.headers.x_opaque_id": "opaque-1772653234", | ||
| "user.name": "elastic", | ||
| "user.realm": "reserved", | ||
| "ecs.version": "1.2.0", | ||
| "service.name": "ES_ECS", | ||
| "event.dataset": "elasticsearch.querylog", | ||
| "process.thread.name": "elasticsearch[node-1][search_coordination][T#6]", | ||
| "log.logger": "elasticsearch.querylog", | ||
| "elasticsearch.cluster.uuid": "gjYgb-uQQAuLmDoKlQInZw", | ||
| "elasticsearch.node.id": "juurGSfgRYGwTP2ttZbtOQ", | ||
| "elasticsearch.node.name": "node-1", | ||
| "elasticsearch.cluster.name": "querying" | ||
| } | ||
| ``` | ||
|
|
||
| ## Finding the logs [finding-query-logs] | ||
|
|
||
| The logs are always emitted on the node that executed the request. These logs can be viewed in the following locations: | ||
|
|
||
| - If [{{es}} monitoring](/deploy-manage/monitor/stack-monitoring.md) is enabled, from [Stack Monitoring](/deploy-manage/monitor/monitoring-data/visualizing-monitoring-data.md). The query logs have the `log.logger` field set to `elasticsearch.querylog`. | ||
| - From the local {{es}} service logs directory. Query log files have a suffix of `_querylog.json` , e.g. `mycluster_querylog.json`. | ||
|
|
||
| ## When and how to use query logging | ||
|
|
||
| While query logging is designed to have as little impact on the performance of your cluster as possible, it will necessarily consume resources needed to create and store the logs. Thus, it is advised to enable query logging only when necessary for troubleshooting or monitoring purposes, and to disable it after the investigation is complete. It is also recommended to set the threshold to avoid logging very quick queries that are of little consequence for cluster performance. | ||
|
Check notice on line 157 in deploy-manage/monitor/logging-configuration/query-logs.md
|
||
|
|
||
| Query logging uses an asynchronous logging mechanism that does not block query execution. As a result, if there are too many incoming queries and the logging system can not store all the logs fast enough, some log entries may be lost. If that is a problem, consider increasing the thresholds to only log the most impactful queries. | ||
|
|
||
| ## Learn more [_learn_more] | ||
|
|
||
| To learn about other ways to optimize your search requests, refer to [tune for search speed](/deploy-manage/production-guidance/optimize-performance/search-speed.md). | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smalyshev could we please add the list the subfields for the user?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It really depends on Security plugin and how request is authorized... So we don't really have any part in this.