Skip to content

Analytic Query logging#139920

Merged
smalyshev merged 88 commits intoelastic:mainfrom
smalyshev:analytics-logging
Feb 13, 2026
Merged

Analytic Query logging#139920
smalyshev merged 88 commits intoelastic:mainfrom
smalyshev:analytics-logging

Conversation

@smalyshev
Copy link
Copy Markdown
Contributor

@smalyshev smalyshev commented Dec 22, 2025

This patch creates framework for generic action logging, serving search, SQL, EQL, ESQL, etc. Enabling logging:

elasticsearch.actionlog.search.enabled=true

Will produce search logs in JSON format like this:

{
	"@timestamp": "2026-02-06T20:22:41.345Z",
	"log.level": "INFO",
	"auth.type": "REALM",
	"elasticsearch.activitylog.hits": 3,
	"elasticsearch.activitylog.indices": "my-index",
	"elasticsearch.activitylog.query": "{\"size\":1,\"fields\":[{\"field\":\"id\"},{\"field\":\"title\"},{\"field\":\"_tier\"}]}",
	"elasticsearch.activitylog.took": 1000000,
	"elasticsearch.activitylog.took_millis": 1,
	"elasticsearch.activitylog.type": "search",
	"event.duration": 1000000,
	"event.outcome": "success",
	"user.name": "elastic",
	"user.realm": "reserved",
	"ecs.version": "1.2.0",
	"service.name": "ES_ECS",
	"event.dataset": "elasticsearch.search_log",
	"process.thread.name": "elasticsearch[node-1][search][T#8]",
	"log.logger": "search.activitylog",
	"elasticsearch.cluster.uuid": "gjYgb-uQQAuLmDoKlQInZw",
	"elasticsearch.node.id": "juurGSfgRYGwTP2ttZbtOQ",
	"elasticsearch.node.name": "node-1",
	"elasticsearch.cluster.name": "querying"
}

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Hi @smalyshev, I've created a changelog YAML for you.

Copy link
Copy Markdown
Contributor

@consulthys consulthys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates.
Added some comments

@Override
public ESLogMessage produce(EqlLogContext context, ActionLoggingFields additionalFields) {
ESLogMessage msg = produceCommon(context, additionalFields);
msg.field(ES_FIELDS_PREFIX + "query", context.getQuery());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since ES_FIELDS_PREFIX is elasticsearch.activitylog. I feel these search-specific fields should go into another sub-section dedicated to search if in the future we were to add more non-search-related activities. Makes sense?
Thoughts @jimczi ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if having query in separate places for different modules is beneficial, but it's possible to do, please tell which one is preferred.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is that the elasticsearch.activitylog. is not about search/query activities specifically. If the activity logs get extended at some point to also include other non-search activities, all the search-specified fields (i.e. took, took_ms, query, indices, etc) should be in their own sub-section (e.g. elasticsearch.activitylog.search.took, etc)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I see what you mean here, but I am not sure how to better configure this space. "search" name would be confusing, as there's separate module "search". So the question is - do we want to have separate section for each module (despite a lot of info being common between them) or we have a section for all "searching/reading/querying" modules and potentially another section for "indexing"?

I think we need to discuss it more in detail, but I don't want to hold this patch for this - I think after we figure it out we'd do a followup if necessary?

@Override
public ESLogMessage produce(EsqlLogContext context, ActionLoggingFields additionalFields) {
ESLogMessage msg = produceCommon(context, additionalFields);
return msg.field(ES_FIELDS_PREFIX + "query", context.getQuery());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as for EQL above and having another sub-section dedicated to search

@Override
public ESLogMessage produce(SqlLogContext context, ActionLoggingFields additionalFields) {
ESLogMessage msg = produceCommon(context, additionalFields);
return msg.field(ES_FIELDS_PREFIX + "query", context.getQuery()).field(ES_FIELDS_PREFIX + "rows", context.getRows());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as for EQL above and having another sub-section dedicated to search

@smalyshev smalyshev linked an issue Feb 11, 2026 that may be closed by this pull request
7 tasks
);

List<? extends ActionLoggingFieldsProvider> slowLogFieldProviders = pluginsService.loadServiceProviders(
List<? extends ActionLoggingFieldsProvider> loggingFieldsProviders = pluginsService.loadServiceProviders(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename ActionLoggingFieldProvider to ActivityLoggingFieldProvider for consistency?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily, they are not strongly linked - any logger can use ActionLoggingFieldProvider (and slowlogs, while they exist, do still use it).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a plan to make slow logs an ActivityLogProducer or is it going to remain it's own thing? It'd be nice to just consolidate all these things as "activity logs" and not have slow logs be a one-off.

Copy link
Copy Markdown
Contributor Author

@smalyshev smalyshev Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That depends on what you mean by "plan". We agree that eventually we'd want all those to merge into the new system, but it's not a high priority right now, though eventually that's where we want to end up. Probably starting with ESQL log, then search slow log, than indexing slow log (indexing is the last because current system doesn't support indexing yet). But we do not have a definite plan of when and who will be doing it. Here's issue for ESQL: #142425 for the rest I don't think it's tracked yet (@naj-h may know more).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could discuss eventually renaming ActionLoggingFieldsProvider if slow logs go away (which may happen in the future) but it's probably not the time yet for this patch.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We agree that eventually we'd want all those to merge into the new system, but it's not a high priority right now, though eventually that's where we want to end up.

Yeah, that's good enough for me. Just wanted to make sure we're aligned that we do want to consolidate these.

smalyshev and others added 7 commits February 12, 2026 15:07
Co-authored-by: Mark Vieira <portugee@gmail.com>
Co-authored-by: Mark Vieira <portugee@gmail.com>
Co-authored-by: Mark Vieira <portugee@gmail.com>
Co-authored-by: Mark Vieira <portugee@gmail.com>
@smalyshev smalyshev merged commit b8804a6 into elastic:main Feb 13, 2026
35 checks passed
@smalyshev smalyshev deleted the analytics-logging branch February 13, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Core/Infra/Logging Log management and logging utilities >enhancement :Search Foundations/Search Catch all for Search Foundations Team:Core/Infra Meta label for core/infra team Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement search analytics logging

6 participants