Skip to content

[ML] Log Rate Analysis: Optimizes & Re-enables text field analysis in contextual insights#244109

Merged
rbrtj merged 6 commits intoelastic:mainfrom
rbrtj:log-rate-analysis-enhancements
Dec 16, 2025
Merged

[ML] Log Rate Analysis: Optimizes & Re-enables text field analysis in contextual insights#244109
rbrtj merged 6 commits intoelastic:mainfrom
rbrtj:log-rate-analysis-enhancements

Conversation

@rbrtj
Copy link
Contributor

@rbrtj rbrtj commented Nov 25, 2025

Summary

Resolves #235562

  • Moves multiple msearch requests to a single search request using a filters agg, making it more efficient.
  • Introduces support for random sampling in category count queries.
  • Enables text field analysis in alerts and contextual insights.

Before:
image

After:
image

@rbrtj
Copy link
Contributor Author

rbrtj commented Nov 25, 2025

/ci

category_counts: {
filters: {
filters: {
'runTask ended no files to process': {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better if this was a generated name like filter_0001 or similar. In x-pack/platform/packages/shared/ml/aiops_log_rate_analysis/queries/fetch_significant_term_p_values.ts we do something similar where we name aggs like aggs[distinct_count_${index}] = ... and aggs[sig_term_p_value_${index}] = ....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated to category_${index} in 451817b


try {
mSearchresponse = await esClient.msearch({ searches }, { signal: abortSignal, maxRetries: 0 });
response = await esClient.search(request, { signal: abortSignal, maxRetries: 0 });
Copy link
Contributor

Choose a reason for hiding this comment

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

Because we raised the category limit to 1000 again, it means this can be a query with up to 1000 filter aggs. We discussed also adding an inner async queue here to split this up into multiple search with each up to 100 filters for example.

Copy link
Contributor Author

@rbrtj rbrtj Dec 12, 2025

Choose a reason for hiding this comment

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

As discussed offline, a single query with up to 1000 filters should be fine.

@rbrtj rbrtj added release_note:fix :ml Team:ML Team label for ML (also use :ml) t// backport:version Backport to applied version labels v9.3.0 v9.2.3 v9.1.9 v8.19.9 labels Dec 12, 2025
@rbrtj rbrtj marked this pull request as ready for review December 12, 2025 10:52
@rbrtj rbrtj requested a review from a team as a code owner December 12, 2025 10:52
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@rbrtj rbrtj requested a review from walterra December 12, 2025 10:52
@rbrtj rbrtj changed the title [ML] Log Rate Analysis: Optimize text field analysis Dec 12, 2025
Copy link
Contributor

@walterra walterra left a comment

Choose a reason for hiding this comment

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

Latest code changes LGTM.

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #115 / Serverless Observability - Deployment-agnostic AI Assistant API integration tests observability AI Assistant tool: retrieve_elastic_doc POST /internal/observability_ai_assistant/chat/complete The second request - Sending the user prompt should send 1 document to the llm
  • [job] [logs] FTR Configs #105 / serverless observability UI - Cases and Rules Serverless Observability Cases Cases list row actions Severity to critical

Metrics [docs]

✅ unchanged

History

cc @rbrtj

Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

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

LGTM. Tested log rate analysis in the ML app and in the custom threshold alert details page to verify there were no regressions.

@rbrtj rbrtj merged commit 651d73a into elastic:main Dec 16, 2025
13 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19, 9.1, 9.2

https://github.com/elastic/kibana/actions/runs/20261500253

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 16, 2025
… contextual insights (elastic#244109)

## Summary

Resolves elastic#235562

- Moves multiple `msearch` requests to a single search request using a
filters agg, making it more efficient.
- Introduces support for random sampling in category count queries.
- Enables text field analysis in alerts and contextual insights.

Before:
<img width="1065" height="893" alt="image"
src="https://github.com/user-attachments/assets/a15bf9b9-4d1a-4bcc-922b-4a6f0f282146"
/>

After:
<img width="1023" height="799" alt="image"
src="https://github.com/user-attachments/assets/55bc46aa-ab91-4867-b5dc-7d7692a62107"
/>

(cherry picked from commit 651d73a)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 16, 2025
… contextual insights (elastic#244109)

## Summary

Resolves elastic#235562

- Moves multiple `msearch` requests to a single search request using a
filters agg, making it more efficient.
- Introduces support for random sampling in category count queries.
- Enables text field analysis in alerts and contextual insights.

Before:
<img width="1065" height="893" alt="image"
src="https://github.com/user-attachments/assets/a15bf9b9-4d1a-4bcc-922b-4a6f0f282146"
/>

After:
<img width="1023" height="799" alt="image"
src="https://github.com/user-attachments/assets/55bc46aa-ab91-4867-b5dc-7d7692a62107"
/>

(cherry picked from commit 651d73a)
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
8.19 Backport failed because of merge conflicts
9.1
9.2

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

node scripts/backport --pr 244109

Questions ?

Please refer to the Backport tool documentation

@rbrtj
Copy link
Contributor Author

rbrtj commented Dec 16, 2025

💚 All backports created successfully

Status Branch Result
8.19

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

rbrtj added a commit to rbrtj/kibana that referenced this pull request Dec 16, 2025
… contextual insights (elastic#244109)

## Summary

Resolves elastic#235562

- Moves multiple `msearch` requests to a single search request using a
filters agg, making it more efficient.
- Introduces support for random sampling in category count queries.
- Enables text field analysis in alerts and contextual insights.

Before:
<img width="1065" height="893" alt="image"
src="https://github.com/user-attachments/assets/a15bf9b9-4d1a-4bcc-922b-4a6f0f282146"
/>

After:
<img width="1023" height="799" alt="image"
src="https://github.com/user-attachments/assets/55bc46aa-ab91-4867-b5dc-7d7692a62107"
/>

(cherry picked from commit 651d73a)

# Conflicts:
#	x-pack/platform/packages/shared/ml/aiops_log_rate_analysis/queries/fetch_categories.test.ts
#	x-pack/platform/packages/shared/ml/aiops_log_rate_analysis/queries/fetch_category_counts.test.ts
#	x-pack/platform/packages/shared/ml/aiops_log_rate_analysis/queries/fetch_category_counts.ts
kibanamachine added a commit that referenced this pull request Dec 16, 2025
…sis in contextual insights (#244109) (#246497)

# Backport

This will backport the following commits from `main` to `9.2`:
- [[ML] Log Rate Analysis: Optimizes & Re-enables text field analysis in
contextual insights
(#244109)](#244109)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Robert
Jaszczurek","email":"92210485+rbrtj@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-12-16T08:33:02Z","message":"[ML]
Log Rate Analysis: Optimizes & Re-enables text field analysis in
contextual insights (#244109)\n\n## Summary\n\nResolves
https://github.com/elastic/kibana/issues/235562\n\n- Moves multiple
`msearch` requests to a single search request using a\nfilters agg,
making it more efficient.\n- Introduces support for random sampling in
category count queries.\n- Enables text field analysis in alerts and
contextual insights.\n\nBefore:\n<img width=\"1065\" height=\"893\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/a15bf9b9-4d1a-4bcc-922b-4a6f0f282146\"\n/>\n\nAfter:\n<img
width=\"1023\" height=\"799\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/55bc46aa-ab91-4867-b5dc-7d7692a62107\"\n/>","sha":"651d73a5fe6d4c04e78f1b2ddaa03c38f3308ef0","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","Team:ML","backport:version","v9.3.0","ci:beta-faster-pr-build","v9.2.3","v9.1.9","v8.19.9"],"title":"[ML]
Log Rate Analysis: Optimizes & Re-enables text field analysis in
contextual
insights","number":244109,"url":"https://github.com/elastic/kibana/pull/244109","mergeCommit":{"message":"[ML]
Log Rate Analysis: Optimizes & Re-enables text field analysis in
contextual insights (#244109)\n\n## Summary\n\nResolves
https://github.com/elastic/kibana/issues/235562\n\n- Moves multiple
`msearch` requests to a single search request using a\nfilters agg,
making it more efficient.\n- Introduces support for random sampling in
category count queries.\n- Enables text field analysis in alerts and
contextual insights.\n\nBefore:\n<img width=\"1065\" height=\"893\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/a15bf9b9-4d1a-4bcc-922b-4a6f0f282146\"\n/>\n\nAfter:\n<img
width=\"1023\" height=\"799\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/55bc46aa-ab91-4867-b5dc-7d7692a62107\"\n/>","sha":"651d73a5fe6d4c04e78f1b2ddaa03c38f3308ef0"}},"sourceBranch":"main","suggestedTargetBranches":["9.2","9.1","8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/244109","number":244109,"mergeCommit":{"message":"[ML]
Log Rate Analysis: Optimizes & Re-enables text field analysis in
contextual insights (#244109)\n\n## Summary\n\nResolves
https://github.com/elastic/kibana/issues/235562\n\n- Moves multiple
`msearch` requests to a single search request using a\nfilters agg,
making it more efficient.\n- Introduces support for random sampling in
category count queries.\n- Enables text field analysis in alerts and
contextual insights.\n\nBefore:\n<img width=\"1065\" height=\"893\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/a15bf9b9-4d1a-4bcc-922b-4a6f0f282146\"\n/>\n\nAfter:\n<img
width=\"1023\" height=\"799\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/55bc46aa-ab91-4867-b5dc-7d7692a62107\"\n/>","sha":"651d73a5fe6d4c04e78f1b2ddaa03c38f3308ef0"}},{"branch":"9.2","label":"v9.2.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.1","label":"v9.1.9","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.9","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Robert Jaszczurek <92210485+rbrtj@users.noreply.github.com>
kibanamachine added a commit that referenced this pull request Dec 16, 2025
…sis in contextual insights (#244109) (#246496)

# Backport

This will backport the following commits from `main` to `9.1`:
- [[ML] Log Rate Analysis: Optimizes & Re-enables text field analysis in
contextual insights
(#244109)](#244109)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Robert
Jaszczurek","email":"92210485+rbrtj@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-12-16T08:33:02Z","message":"[ML]
Log Rate Analysis: Optimizes & Re-enables text field analysis in
contextual insights (#244109)\n\n## Summary\n\nResolves
https://github.com/elastic/kibana/issues/235562\n\n- Moves multiple
`msearch` requests to a single search request using a\nfilters agg,
making it more efficient.\n- Introduces support for random sampling in
category count queries.\n- Enables text field analysis in alerts and
contextual insights.\n\nBefore:\n<img width=\"1065\" height=\"893\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/a15bf9b9-4d1a-4bcc-922b-4a6f0f282146\"\n/>\n\nAfter:\n<img
width=\"1023\" height=\"799\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/55bc46aa-ab91-4867-b5dc-7d7692a62107\"\n/>","sha":"651d73a5fe6d4c04e78f1b2ddaa03c38f3308ef0","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","Team:ML","backport:version","v9.3.0","ci:beta-faster-pr-build","v9.2.3","v9.1.9","v8.19.9"],"title":"[ML]
Log Rate Analysis: Optimizes & Re-enables text field analysis in
contextual
insights","number":244109,"url":"https://github.com/elastic/kibana/pull/244109","mergeCommit":{"message":"[ML]
Log Rate Analysis: Optimizes & Re-enables text field analysis in
contextual insights (#244109)\n\n## Summary\n\nResolves
https://github.com/elastic/kibana/issues/235562\n\n- Moves multiple
`msearch` requests to a single search request using a\nfilters agg,
making it more efficient.\n- Introduces support for random sampling in
category count queries.\n- Enables text field analysis in alerts and
contextual insights.\n\nBefore:\n<img width=\"1065\" height=\"893\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/a15bf9b9-4d1a-4bcc-922b-4a6f0f282146\"\n/>\n\nAfter:\n<img
width=\"1023\" height=\"799\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/55bc46aa-ab91-4867-b5dc-7d7692a62107\"\n/>","sha":"651d73a5fe6d4c04e78f1b2ddaa03c38f3308ef0"}},"sourceBranch":"main","suggestedTargetBranches":["9.2","9.1","8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/244109","number":244109,"mergeCommit":{"message":"[ML]
Log Rate Analysis: Optimizes & Re-enables text field analysis in
contextual insights (#244109)\n\n## Summary\n\nResolves
https://github.com/elastic/kibana/issues/235562\n\n- Moves multiple
`msearch` requests to a single search request using a\nfilters agg,
making it more efficient.\n- Introduces support for random sampling in
category count queries.\n- Enables text field analysis in alerts and
contextual insights.\n\nBefore:\n<img width=\"1065\" height=\"893\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/a15bf9b9-4d1a-4bcc-922b-4a6f0f282146\"\n/>\n\nAfter:\n<img
width=\"1023\" height=\"799\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/55bc46aa-ab91-4867-b5dc-7d7692a62107\"\n/>","sha":"651d73a5fe6d4c04e78f1b2ddaa03c38f3308ef0"}},{"branch":"9.2","label":"v9.2.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.1","label":"v9.1.9","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.9","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Robert Jaszczurek <92210485+rbrtj@users.noreply.github.com>
rbrtj added a commit that referenced this pull request Dec 16, 2025
…ysis in contextual insights (#244109) (#246509)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[ML] Log Rate Analysis: Optimizes & Re-enables text field analysis in
contextual insights
(#244109)](#244109)

<!--- Backport version: 10.2.0 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Robert
Jaszczurek","email":"92210485+rbrtj@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-12-16T08:33:02Z","message":"[ML]
Log Rate Analysis: Optimizes & Re-enables text field analysis in
contextual insights (#244109)\n\n## Summary\n\nResolves
https://github.com/elastic/kibana/issues/235562\n\n- Moves multiple
`msearch` requests to a single search request using a\nfilters agg,
making it more efficient.\n- Introduces support for random sampling in
category count queries.\n- Enables text field analysis in alerts and
contextual insights.\n\nBefore:\n<img width=\"1065\" height=\"893\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/a15bf9b9-4d1a-4bcc-922b-4a6f0f282146\"\n/>\n\nAfter:\n<img
width=\"1023\" height=\"799\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/55bc46aa-ab91-4867-b5dc-7d7692a62107\"\n/>","sha":"651d73a5fe6d4c04e78f1b2ddaa03c38f3308ef0","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","Team:ML","backport:version","v9.3.0","ci:beta-faster-pr-build","v9.2.3","v9.1.9","v8.19.9"],"title":"[ML]
Log Rate Analysis: Optimizes & Re-enables text field analysis in
contextual
insights","number":244109,"url":"https://github.com/elastic/kibana/pull/244109","mergeCommit":{"message":"[ML]
Log Rate Analysis: Optimizes & Re-enables text field analysis in
contextual insights (#244109)\n\n## Summary\n\nResolves
https://github.com/elastic/kibana/issues/235562\n\n- Moves multiple
`msearch` requests to a single search request using a\nfilters agg,
making it more efficient.\n- Introduces support for random sampling in
category count queries.\n- Enables text field analysis in alerts and
contextual insights.\n\nBefore:\n<img width=\"1065\" height=\"893\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/a15bf9b9-4d1a-4bcc-922b-4a6f0f282146\"\n/>\n\nAfter:\n<img
width=\"1023\" height=\"799\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/55bc46aa-ab91-4867-b5dc-7d7692a62107\"\n/>","sha":"651d73a5fe6d4c04e78f1b2ddaa03c38f3308ef0"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/244109","number":244109,"mergeCommit":{"message":"[ML]
Log Rate Analysis: Optimizes & Re-enables text field analysis in
contextual insights (#244109)\n\n## Summary\n\nResolves
https://github.com/elastic/kibana/issues/235562\n\n- Moves multiple
`msearch` requests to a single search request using a\nfilters agg,
making it more efficient.\n- Introduces support for random sampling in
category count queries.\n- Enables text field analysis in alerts and
contextual insights.\n\nBefore:\n<img width=\"1065\" height=\"893\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/a15bf9b9-4d1a-4bcc-922b-4a6f0f282146\"\n/>\n\nAfter:\n<img
width=\"1023\" height=\"799\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/55bc46aa-ab91-4867-b5dc-7d7692a62107\"\n/>","sha":"651d73a5fe6d4c04e78f1b2ddaa03c38f3308ef0"}},{"branch":"9.2","label":"v9.2.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/246497","number":246497,"state":"OPEN"},{"branch":"9.1","label":"v9.1.9","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/246496","number":246496,"state":"OPEN"},{"branch":"8.19","label":"v8.19.9","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels :ml release_note:fix Team:ML Team label for ML (also use :ml) t// v8.19.9 v9.1.9 v9.2.3 v9.3.0

5 participants