Skip to content

[Security Solution] Fix "too many clauses" error on prebuilt rules installation page #223240

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

Conversation

nikitaindik
Copy link
Contributor

@nikitaindik nikitaindik commented Jun 10, 2025

Resolves: #223399

Summary

This PR fixes an error on the "Add Elastic rules" page. The error is shown when running a local dev environment from main branch and going to the "Add Elastic rules" page.

Screenshot 2025-06-10 at 11 28 19

Changes

PR updates methods of PrebuiltRuleAssetsClient to split requests to ES into smaller chunks to avoid the error.

Cause

Kibana makes a search request to ES with a filter that has too many clauses, so ES rejects with an error.

More specifically, /prebuilt_rules/installation/_review route handler calls PrebuiltRuleAssetsClient.fetchAssetsByVersion to fetch all installable rules. To do this, we construct a request with thousands of clauses in a filter. ES counts the number of clauses in a filter and rejects because it's bigger than maxClauseCount. maxClauseCount value is computed dynamically by ES and its size depends on hardware and available resources (docs, code). The minimum value for maxClauseCount is 1024.

Why it didn't fail before

Two reasons:

  1. ES changed how maxClauseCount is computed. They've recently merged a PR that made queries against numeric types count three times towards the maxClauseCount limit. They plan to revert the change in this PR.
  2. Prebuilt rule packages are growing bigger with each version, resulting in a bigger number of clauses. I've tested behaviour with ES change in place on different package versions:
  • 8.17.1 (contains 1262 rule versions) - no "too many clauses" error
  • 8.18.1 (contains 1356 rule versions) - causes "too many clauses" error
  • 9.0.1 (also contains 1356 rule versions) - causes "too many clauses" error
    The precise number of versions that start to cause errors is 1293 on my laptop.

So even if ES team rolls back their change, we still need to make sure we don't go over the limit with ever-growing prebuilt rule package sizes.

@nikitaindik nikitaindik marked this pull request as ready for review June 11, 2025 12:49
@nikitaindik nikitaindik requested a review from a team as a code owner June 11, 2025 12:49
@nikitaindik nikitaindik requested review from jkelas and maximpn and removed request for jkelas June 11, 2025 12:49
@nikitaindik nikitaindik self-assigned this Jun 11, 2025
@nikitaindik nikitaindik added Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. labels Jun 11, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detections-response (Team:Detections and Resp)

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@nikitaindik nikitaindik added bug Fixes for quality problems that affect the customer experience Team:Detection Rule Management Security Detection Rule Management Team labels Jun 11, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detection-rule-management (Team:Detection Rule Management)

@nikitaindik nikitaindik added v9.1.0 v8.19.0 v9.0.3 v8.18.3 backport:version Backport to applied version labels Feature:Prebuilt Detection Rules Security Solution Prebuilt Detection Rules area release_note:skip Skip the PR/issue when compiling release notes labels Jun 11, 2025
Copy link
Contributor

@maximpn maximpn left a comment

Choose a reason for hiding this comment

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

@nikitaindik and I Zoomed over this PR. We agreed that having better encapsulation of the chunking logic will help to improve maintainability. On top of that the clauses number calculation happens at Lucene codebase make it opaque for Kibana. The following should be done

  • filter chunking logic should be moved out to a separate function accepting items, a mapper function and the number of clauses per item
  • it's good to have a function to perform an action on chunks like fetchLatestVersionInfo() or find some results
  • extra comments are required to provide better understanding of the problem

@nikitaindik nikitaindik requested a review from maximpn June 16, 2025 14:25
@nikitaindik
Copy link
Contributor Author

@maximpn Refactored as per our discussion over Zoom. Please take a look.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

cc @nikitaindik

Copy link
Contributor

@maximpn maximpn left a comment

Choose a reason for hiding this comment

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

@nikitaindik Thanks for making improvements to the implementation 🙏

The renewed code looks shorter and cleaner 👍

@nikitaindik nikitaindik merged commit 482953d into elastic:main Jun 17, 2025
10 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.18, 8.19, 9.0

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

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jun 17, 2025
…stallation page (elastic#223240)

**Resolves: elastic#223399

## Summary
This PR fixes an error on the "Add Elastic rules" page. The error is
shown when running a local dev environment from `main` branch and going
to the "Add Elastic rules" page.

<img width="1741" alt="Screenshot 2025-06-10 at 11 28 19"
src="https://github.com/user-attachments/assets/f8f81f88-3749-491f-bcdb-cd51f465bda6"
/>

## Changes
PR updates methods of `PrebuiltRuleAssetsClient` to split requests to ES
into smaller chunks to avoid the error.

## Cause
Kibana makes a search request to ES with a filter that has too many
clauses, so ES rejects with an error.

More specifically, `/prebuilt_rules/installation/_review` route handler
calls `PrebuiltRuleAssetsClient.fetchAssetsByVersion` to fetch all
installable rules. To do this, we construct a request with thousands of
clauses in a filter. ES counts the number of clauses in a filter and
rejects because it's bigger than `maxClauseCount`. `maxClauseCount`
value is computed dynamically by ES and its size depends on hardware and
available resources
([docs](https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-settings.html),
[code](https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/search/SearchUtils.java)).
The minimum value for `maxClauseCount` is 1024.

## Why it didn't fail before
Two reasons:
1. ES changed how `maxClauseCount` is computed. They've recently merged
a [PR](elastic/elasticsearch#128293) that made
queries against numeric types count three times towards the
`maxClauseCount` limit. They plan to revert the change in [this
PR](elastic/elasticsearch#129206).
2. Prebuilt rule packages are growing bigger with each version,
resulting in a bigger number of clauses. I've tested behaviour with ES
change in place on different package versions:
- 8.17.1 (contains 1262 rule versions) - no "too many clauses" error
- 8.18.1 (contains 1356 rule versions) - causes "too many clauses" error
- 9.0.1 (also contains 1356 rule versions) - causes "too many clauses"
error
The precise number of versions that start to cause errors is 1293 on my
laptop.

So even if ES team rolls back their change, we still need to make sure
we don't go over the limit with ever-growing prebuilt rule package
sizes.

(cherry picked from commit 482953d)
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
8.18 Backport failed because of merge conflicts
8.19
9.0 Backport failed because of merge conflicts

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

Manual backport

To create the backport manually run:

node scripts/backport --pr 223240

Questions ?

Please refer to the Backport tool documentation

nikitaindik added a commit to nikitaindik/kibana that referenced this pull request Jun 17, 2025
…stallation page (elastic#223240)

**Resolves: elastic#223399

## Summary
This PR fixes an error on the "Add Elastic rules" page. The error is
shown when running a local dev environment from `main` branch and going
to the "Add Elastic rules" page.

<img width="1741" alt="Screenshot 2025-06-10 at 11 28 19"
src="https://github.com/user-attachments/assets/f8f81f88-3749-491f-bcdb-cd51f465bda6"
/>

## Changes
PR updates methods of `PrebuiltRuleAssetsClient` to split requests to ES
into smaller chunks to avoid the error.

## Cause
Kibana makes a search request to ES with a filter that has too many
clauses, so ES rejects with an error.

More specifically, `/prebuilt_rules/installation/_review` route handler
calls `PrebuiltRuleAssetsClient.fetchAssetsByVersion` to fetch all
installable rules. To do this, we construct a request with thousands of
clauses in a filter. ES counts the number of clauses in a filter and
rejects because it's bigger than `maxClauseCount`. `maxClauseCount`
value is computed dynamically by ES and its size depends on hardware and
available resources
([docs](https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-settings.html),
[code](https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/search/SearchUtils.java)).
The minimum value for `maxClauseCount` is 1024.

## Why it didn't fail before
Two reasons:
1. ES changed how `maxClauseCount` is computed. They've recently merged
a [PR](elastic/elasticsearch#128293) that made
queries against numeric types count three times towards the
`maxClauseCount` limit. They plan to revert the change in [this
PR](elastic/elasticsearch#129206).
2. Prebuilt rule packages are growing bigger with each version,
resulting in a bigger number of clauses. I've tested behaviour with ES
change in place on different package versions:
- 8.17.1 (contains 1262 rule versions) - no "too many clauses" error
- 8.18.1 (contains 1356 rule versions) - causes "too many clauses" error
- 9.0.1 (also contains 1356 rule versions) - causes "too many clauses"
error
The precise number of versions that start to cause errors is 1293 on my
laptop.

So even if ES team rolls back their change, we still need to make sure
we don't go over the limit with ever-growing prebuilt rule package
sizes.

(cherry picked from commit 482953d)

# Conflicts:
#	x-pack/solutions/security/plugins/security_solution/server/lib/detection_engine/prebuilt_rules/logic/rule_assets/prebuilt_rule_assets_client.ts
@nikitaindik
Copy link
Contributor Author

💔 Some backports could not be created

Status Branch Result
9.0
8.18 Conflict resolution was aborted by the user

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

Manual backport

To create the backport manually run:

node scripts/backport --pr 223240

Questions ?

Please refer to the Backport tool documentation

@nikitaindik
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.18

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

Questions ?

Please refer to the Backport tool documentation

nikitaindik added a commit to nikitaindik/kibana that referenced this pull request Jun 17, 2025
…stallation page (elastic#223240)

**Resolves: elastic#223399

## Summary
This PR fixes an error on the "Add Elastic rules" page. The error is
shown when running a local dev environment from `main` branch and going
to the "Add Elastic rules" page.

<img width="1741" alt="Screenshot 2025-06-10 at 11 28 19"
src="https://github.com/user-attachments/assets/f8f81f88-3749-491f-bcdb-cd51f465bda6"
/>

## Changes
PR updates methods of `PrebuiltRuleAssetsClient` to split requests to ES
into smaller chunks to avoid the error.

## Cause
Kibana makes a search request to ES with a filter that has too many
clauses, so ES rejects with an error.

More specifically, `/prebuilt_rules/installation/_review` route handler
calls `PrebuiltRuleAssetsClient.fetchAssetsByVersion` to fetch all
installable rules. To do this, we construct a request with thousands of
clauses in a filter. ES counts the number of clauses in a filter and
rejects because it's bigger than `maxClauseCount`. `maxClauseCount`
value is computed dynamically by ES and its size depends on hardware and
available resources
([docs](https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-settings.html),
[code](https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/search/SearchUtils.java)).
The minimum value for `maxClauseCount` is 1024.

## Why it didn't fail before
Two reasons:
1. ES changed how `maxClauseCount` is computed. They've recently merged
a [PR](elastic/elasticsearch#128293) that made
queries against numeric types count three times towards the
`maxClauseCount` limit. They plan to revert the change in [this
PR](elastic/elasticsearch#129206).
2. Prebuilt rule packages are growing bigger with each version,
resulting in a bigger number of clauses. I've tested behaviour with ES
change in place on different package versions:
- 8.17.1 (contains 1262 rule versions) - no "too many clauses" error
- 8.18.1 (contains 1356 rule versions) - causes "too many clauses" error
- 9.0.1 (also contains 1356 rule versions) - causes "too many clauses"
error
The precise number of versions that start to cause errors is 1293 on my
laptop.

So even if ES team rolls back their change, we still need to make sure
we don't go over the limit with ever-growing prebuilt rule package
sizes.

(cherry picked from commit 482953d)

# Conflicts:
#	x-pack/solutions/security/plugins/security_solution/server/lib/detection_engine/prebuilt_rules/logic/rule_assets/prebuilt_rule_assets_client.ts
kibanamachine added a commit that referenced this pull request Jun 17, 2025
…ules installation page (#223240) (#224269)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[Security Solution] Fix "too many clauses" error on prebuilt rules
installation page
(#223240)](#223240)

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

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

<!--BACKPORT [{"author":{"name":"Nikita
Indik","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-06-17T14:14:56Z","message":"[Security
Solution] Fix \"too many clauses\" error on prebuilt rules installation
page (#223240)\n\n**Resolves:
https://github.com/elastic/kibana/issues/223399**\n\n## Summary\nThis PR
fixes an error on the \"Add Elastic rules\" page. The error is\nshown
when running a local dev environment from `main` branch and going\nto
the \"Add Elastic rules\" page.\n\n<img width=\"1741\" alt=\"Screenshot
2025-06-10 at 11 28
19\"\nsrc=\"https://github.com/user-attachments/assets/f8f81f88-3749-491f-bcdb-cd51f465bda6\"\n/>\n\n##
Changes\nPR updates methods of `PrebuiltRuleAssetsClient` to split
requests to ES\ninto smaller chunks to avoid the error.\n\n##
Cause\nKibana makes a search request to ES with a filter that has too
many\nclauses, so ES rejects with an error.\n\nMore specifically,
`/prebuilt_rules/installation/_review` route handler\ncalls
`PrebuiltRuleAssetsClient.fetchAssetsByVersion` to fetch
all\ninstallable rules. To do this, we construct a request with
thousands of\nclauses in a filter. ES counts the number of clauses in a
filter and\nrejects because it's bigger than `maxClauseCount`.
`maxClauseCount`\nvalue is computed dynamically by ES and its size
depends on hardware and\navailable
resources\n([docs](https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-settings.html),\n[code](https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/search/SearchUtils.java)).\nThe
minimum value for `maxClauseCount` is 1024.\n\n## Why it didn't fail
before\nTwo reasons:\n1. ES changed how `maxClauseCount` is computed.
They've recently merged\na
[PR](elastic/elasticsearch#128293) that
made\nqueries against numeric types count three times towards
the\n`maxClauseCount` limit. They plan to revert the change in
[this\nPR](https://github.com/elastic/elasticsearch/pull/129206).\n2.
Prebuilt rule packages are growing bigger with each version,\nresulting
in a bigger number of clauses. I've tested behaviour with ES\nchange in
place on different package versions:\n- 8.17.1 (contains 1262 rule
versions) - no \"too many clauses\" error\n- 8.18.1 (contains 1356 rule
versions) - causes \"too many clauses\" error\n- 9.0.1 (also contains
1356 rule versions) - causes \"too many clauses\"\nerror\nThe precise
number of versions that start to cause errors is 1293 on
my\nlaptop.\n\nSo even if ES team rolls back their change, we still need
to make sure\nwe don't go over the limit with ever-growing prebuilt rule
package\nsizes.","sha":"482953ddc5a9e1494a3182c9cedfa4214179a297","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:Detections
and Resp","Team: SecuritySolution","Team:Detection Rule
Management","Feature:Prebuilt Detection
Rules","backport:version","v9.1.0","v8.19.0","v9.0.3","v8.18.3"],"title":"[Security
Solution] Fix \"too many clauses\" error on prebuilt rules installation
page","number":223240,"url":"https://github.com/elastic/kibana/pull/223240","mergeCommit":{"message":"[Security
Solution] Fix \"too many clauses\" error on prebuilt rules installation
page (#223240)\n\n**Resolves:
https://github.com/elastic/kibana/issues/223399**\n\n## Summary\nThis PR
fixes an error on the \"Add Elastic rules\" page. The error is\nshown
when running a local dev environment from `main` branch and going\nto
the \"Add Elastic rules\" page.\n\n<img width=\"1741\" alt=\"Screenshot
2025-06-10 at 11 28
19\"\nsrc=\"https://github.com/user-attachments/assets/f8f81f88-3749-491f-bcdb-cd51f465bda6\"\n/>\n\n##
Changes\nPR updates methods of `PrebuiltRuleAssetsClient` to split
requests to ES\ninto smaller chunks to avoid the error.\n\n##
Cause\nKibana makes a search request to ES with a filter that has too
many\nclauses, so ES rejects with an error.\n\nMore specifically,
`/prebuilt_rules/installation/_review` route handler\ncalls
`PrebuiltRuleAssetsClient.fetchAssetsByVersion` to fetch
all\ninstallable rules. To do this, we construct a request with
thousands of\nclauses in a filter. ES counts the number of clauses in a
filter and\nrejects because it's bigger than `maxClauseCount`.
`maxClauseCount`\nvalue is computed dynamically by ES and its size
depends on hardware and\navailable
resources\n([docs](https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-settings.html),\n[code](https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/search/SearchUtils.java)).\nThe
minimum value for `maxClauseCount` is 1024.\n\n## Why it didn't fail
before\nTwo reasons:\n1. ES changed how `maxClauseCount` is computed.
They've recently merged\na
[PR](elastic/elasticsearch#128293) that
made\nqueries against numeric types count three times towards
the\n`maxClauseCount` limit. They plan to revert the change in
[this\nPR](https://github.com/elastic/elasticsearch/pull/129206).\n2.
Prebuilt rule packages are growing bigger with each version,\nresulting
in a bigger number of clauses. I've tested behaviour with ES\nchange in
place on different package versions:\n- 8.17.1 (contains 1262 rule
versions) - no \"too many clauses\" error\n- 8.18.1 (contains 1356 rule
versions) - causes \"too many clauses\" error\n- 9.0.1 (also contains
1356 rule versions) - causes \"too many clauses\"\nerror\nThe precise
number of versions that start to cause errors is 1293 on
my\nlaptop.\n\nSo even if ES team rolls back their change, we still need
to make sure\nwe don't go over the limit with ever-growing prebuilt rule
package\nsizes.","sha":"482953ddc5a9e1494a3182c9cedfa4214179a297"}},"sourceBranch":"main","suggestedTargetBranches":["8.19","9.0","8.18"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/223240","number":223240,"mergeCommit":{"message":"[Security
Solution] Fix \"too many clauses\" error on prebuilt rules installation
page (#223240)\n\n**Resolves:
https://github.com/elastic/kibana/issues/223399**\n\n## Summary\nThis PR
fixes an error on the \"Add Elastic rules\" page. The error is\nshown
when running a local dev environment from `main` branch and going\nto
the \"Add Elastic rules\" page.\n\n<img width=\"1741\" alt=\"Screenshot
2025-06-10 at 11 28
19\"\nsrc=\"https://github.com/user-attachments/assets/f8f81f88-3749-491f-bcdb-cd51f465bda6\"\n/>\n\n##
Changes\nPR updates methods of `PrebuiltRuleAssetsClient` to split
requests to ES\ninto smaller chunks to avoid the error.\n\n##
Cause\nKibana makes a search request to ES with a filter that has too
many\nclauses, so ES rejects with an error.\n\nMore specifically,
`/prebuilt_rules/installation/_review` route handler\ncalls
`PrebuiltRuleAssetsClient.fetchAssetsByVersion` to fetch
all\ninstallable rules. To do this, we construct a request with
thousands of\nclauses in a filter. ES counts the number of clauses in a
filter and\nrejects because it's bigger than `maxClauseCount`.
`maxClauseCount`\nvalue is computed dynamically by ES and its size
depends on hardware and\navailable
resources\n([docs](https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-settings.html),\n[code](https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/search/SearchUtils.java)).\nThe
minimum value for `maxClauseCount` is 1024.\n\n## Why it didn't fail
before\nTwo reasons:\n1. ES changed how `maxClauseCount` is computed.
They've recently merged\na
[PR](elastic/elasticsearch#128293) that
made\nqueries against numeric types count three times towards
the\n`maxClauseCount` limit. They plan to revert the change in
[this\nPR](https://github.com/elastic/elasticsearch/pull/129206).\n2.
Prebuilt rule packages are growing bigger with each version,\nresulting
in a bigger number of clauses. I've tested behaviour with ES\nchange in
place on different package versions:\n- 8.17.1 (contains 1262 rule
versions) - no \"too many clauses\" error\n- 8.18.1 (contains 1356 rule
versions) - causes \"too many clauses\" error\n- 9.0.1 (also contains
1356 rule versions) - causes \"too many clauses\"\nerror\nThe precise
number of versions that start to cause errors is 1293 on
my\nlaptop.\n\nSo even if ES team rolls back their change, we still need
to make sure\nwe don't go over the limit with ever-growing prebuilt rule
package\nsizes.","sha":"482953ddc5a9e1494a3182c9cedfa4214179a297"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Nikita Indik <[email protected]>
nikitaindik added a commit that referenced this pull request Jun 18, 2025
…les installation page (#223240) (#224282)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[Security Solution] Fix "too many clauses" error on prebuilt rules
installation page
(#223240)](#223240)

<!--- Backport version: 10.0.1 -->

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

<!--BACKPORT [{"author":{"name":"Nikita
Indik","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-06-17T14:14:56Z","message":"[Security
Solution] Fix \"too many clauses\" error on prebuilt rules installation
page (#223240)\n\n**Resolves:
https://github.com/elastic/kibana/issues/223399**\n\n## Summary\nThis PR
fixes an error on the \"Add Elastic rules\" page. The error is\nshown
when running a local dev environment from `main` branch and going\nto
the \"Add Elastic rules\" page.\n\n<img width=\"1741\" alt=\"Screenshot
2025-06-10 at 11 28
19\"\nsrc=\"https://github.com/user-attachments/assets/f8f81f88-3749-491f-bcdb-cd51f465bda6\"\n/>\n\n##
Changes\nPR updates methods of `PrebuiltRuleAssetsClient` to split
requests to ES\ninto smaller chunks to avoid the error.\n\n##
Cause\nKibana makes a search request to ES with a filter that has too
many\nclauses, so ES rejects with an error.\n\nMore specifically,
`/prebuilt_rules/installation/_review` route handler\ncalls
`PrebuiltRuleAssetsClient.fetchAssetsByVersion` to fetch
all\ninstallable rules. To do this, we construct a request with
thousands of\nclauses in a filter. ES counts the number of clauses in a
filter and\nrejects because it's bigger than `maxClauseCount`.
`maxClauseCount`\nvalue is computed dynamically by ES and its size
depends on hardware and\navailable
resources\n([docs](https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-settings.html),\n[code](https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/search/SearchUtils.java)).\nThe
minimum value for `maxClauseCount` is 1024.\n\n## Why it didn't fail
before\nTwo reasons:\n1. ES changed how `maxClauseCount` is computed.
They've recently merged\na
[PR](elastic/elasticsearch#128293) that
made\nqueries against numeric types count three times towards
the\n`maxClauseCount` limit. They plan to revert the change in
[this\nPR](https://github.com/elastic/elasticsearch/pull/129206).\n2.
Prebuilt rule packages are growing bigger with each version,\nresulting
in a bigger number of clauses. I've tested behaviour with ES\nchange in
place on different package versions:\n- 8.17.1 (contains 1262 rule
versions) - no \"too many clauses\" error\n- 8.18.1 (contains 1356 rule
versions) - causes \"too many clauses\" error\n- 9.0.1 (also contains
1356 rule versions) - causes \"too many clauses\"\nerror\nThe precise
number of versions that start to cause errors is 1293 on
my\nlaptop.\n\nSo even if ES team rolls back their change, we still need
to make sure\nwe don't go over the limit with ever-growing prebuilt rule
package\nsizes.","sha":"482953ddc5a9e1494a3182c9cedfa4214179a297","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:Detections
and Resp","Team: SecuritySolution","Team:Detection Rule
Management","Feature:Prebuilt Detection
Rules","backport:version","v9.1.0","v8.19.0","v9.0.3","v8.18.3"],"title":"[Security
Solution] Fix \"too many clauses\" error on prebuilt rules installation
page","number":223240,"url":"https://github.com/elastic/kibana/pull/223240","mergeCommit":{"message":"[Security
Solution] Fix \"too many clauses\" error on prebuilt rules installation
page (#223240)\n\n**Resolves:
https://github.com/elastic/kibana/issues/223399**\n\n## Summary\nThis PR
fixes an error on the \"Add Elastic rules\" page. The error is\nshown
when running a local dev environment from `main` branch and going\nto
the \"Add Elastic rules\" page.\n\n<img width=\"1741\" alt=\"Screenshot
2025-06-10 at 11 28
19\"\nsrc=\"https://github.com/user-attachments/assets/f8f81f88-3749-491f-bcdb-cd51f465bda6\"\n/>\n\n##
Changes\nPR updates methods of `PrebuiltRuleAssetsClient` to split
requests to ES\ninto smaller chunks to avoid the error.\n\n##
Cause\nKibana makes a search request to ES with a filter that has too
many\nclauses, so ES rejects with an error.\n\nMore specifically,
`/prebuilt_rules/installation/_review` route handler\ncalls
`PrebuiltRuleAssetsClient.fetchAssetsByVersion` to fetch
all\ninstallable rules. To do this, we construct a request with
thousands of\nclauses in a filter. ES counts the number of clauses in a
filter and\nrejects because it's bigger than `maxClauseCount`.
`maxClauseCount`\nvalue is computed dynamically by ES and its size
depends on hardware and\navailable
resources\n([docs](https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-settings.html),\n[code](https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/search/SearchUtils.java)).\nThe
minimum value for `maxClauseCount` is 1024.\n\n## Why it didn't fail
before\nTwo reasons:\n1. ES changed how `maxClauseCount` is computed.
They've recently merged\na
[PR](elastic/elasticsearch#128293) that
made\nqueries against numeric types count three times towards
the\n`maxClauseCount` limit. They plan to revert the change in
[this\nPR](https://github.com/elastic/elasticsearch/pull/129206).\n2.
Prebuilt rule packages are growing bigger with each version,\nresulting
in a bigger number of clauses. I've tested behaviour with ES\nchange in
place on different package versions:\n- 8.17.1 (contains 1262 rule
versions) - no \"too many clauses\" error\n- 8.18.1 (contains 1356 rule
versions) - causes \"too many clauses\" error\n- 9.0.1 (also contains
1356 rule versions) - causes \"too many clauses\"\nerror\nThe precise
number of versions that start to cause errors is 1293 on
my\nlaptop.\n\nSo even if ES team rolls back their change, we still need
to make sure\nwe don't go over the limit with ever-growing prebuilt rule
package\nsizes.","sha":"482953ddc5a9e1494a3182c9cedfa4214179a297"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/223240","number":223240,"mergeCommit":{"message":"[Security
Solution] Fix \"too many clauses\" error on prebuilt rules installation
page (#223240)\n\n**Resolves:
https://github.com/elastic/kibana/issues/223399**\n\n## Summary\nThis PR
fixes an error on the \"Add Elastic rules\" page. The error is\nshown
when running a local dev environment from `main` branch and going\nto
the \"Add Elastic rules\" page.\n\n<img width=\"1741\" alt=\"Screenshot
2025-06-10 at 11 28
19\"\nsrc=\"https://github.com/user-attachments/assets/f8f81f88-3749-491f-bcdb-cd51f465bda6\"\n/>\n\n##
Changes\nPR updates methods of `PrebuiltRuleAssetsClient` to split
requests to ES\ninto smaller chunks to avoid the error.\n\n##
Cause\nKibana makes a search request to ES with a filter that has too
many\nclauses, so ES rejects with an error.\n\nMore specifically,
`/prebuilt_rules/installation/_review` route handler\ncalls
`PrebuiltRuleAssetsClient.fetchAssetsByVersion` to fetch
all\ninstallable rules. To do this, we construct a request with
thousands of\nclauses in a filter. ES counts the number of clauses in a
filter and\nrejects because it's bigger than `maxClauseCount`.
`maxClauseCount`\nvalue is computed dynamically by ES and its size
depends on hardware and\navailable
resources\n([docs](https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-settings.html),\n[code](https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/search/SearchUtils.java)).\nThe
minimum value for `maxClauseCount` is 1024.\n\n## Why it didn't fail
before\nTwo reasons:\n1. ES changed how `maxClauseCount` is computed.
They've recently merged\na
[PR](elastic/elasticsearch#128293) that
made\nqueries against numeric types count three times towards
the\n`maxClauseCount` limit. They plan to revert the change in
[this\nPR](https://github.com/elastic/elasticsearch/pull/129206).\n2.
Prebuilt rule packages are growing bigger with each version,\nresulting
in a bigger number of clauses. I've tested behaviour with ES\nchange in
place on different package versions:\n- 8.17.1 (contains 1262 rule
versions) - no \"too many clauses\" error\n- 8.18.1 (contains 1356 rule
versions) - causes \"too many clauses\" error\n- 9.0.1 (also contains
1356 rule versions) - causes \"too many clauses\"\nerror\nThe precise
number of versions that start to cause errors is 1293 on
my\nlaptop.\n\nSo even if ES team rolls back their change, we still need
to make sure\nwe don't go over the limit with ever-growing prebuilt rule
package\nsizes.","sha":"482953ddc5a9e1494a3182c9cedfa4214179a297"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/224269","number":224269,"state":"OPEN"},{"branch":"9.0","label":"v9.0.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
nikitaindik added a commit that referenced this pull request Jun 18, 2025
…ules installation page (#223240) (#224283)

# Backport

This will backport the following commits from `main` to `8.18`:
- [[Security Solution] Fix "too many clauses" error on prebuilt rules
installation page
(#223240)](#223240)

<!--- Backport version: 10.0.1 -->

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

<!--BACKPORT [{"author":{"name":"Nikita
Indik","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-06-17T14:14:56Z","message":"[Security
Solution] Fix \"too many clauses\" error on prebuilt rules installation
page (#223240)\n\n**Resolves:
https://github.com/elastic/kibana/issues/223399**\n\n## Summary\nThis PR
fixes an error on the \"Add Elastic rules\" page. The error is\nshown
when running a local dev environment from `main` branch and going\nto
the \"Add Elastic rules\" page.\n\n<img width=\"1741\" alt=\"Screenshot
2025-06-10 at 11 28
19\"\nsrc=\"https://github.com/user-attachments/assets/f8f81f88-3749-491f-bcdb-cd51f465bda6\"\n/>\n\n##
Changes\nPR updates methods of `PrebuiltRuleAssetsClient` to split
requests to ES\ninto smaller chunks to avoid the error.\n\n##
Cause\nKibana makes a search request to ES with a filter that has too
many\nclauses, so ES rejects with an error.\n\nMore specifically,
`/prebuilt_rules/installation/_review` route handler\ncalls
`PrebuiltRuleAssetsClient.fetchAssetsByVersion` to fetch
all\ninstallable rules. To do this, we construct a request with
thousands of\nclauses in a filter. ES counts the number of clauses in a
filter and\nrejects because it's bigger than `maxClauseCount`.
`maxClauseCount`\nvalue is computed dynamically by ES and its size
depends on hardware and\navailable
resources\n([docs](https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-settings.html),\n[code](https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/search/SearchUtils.java)).\nThe
minimum value for `maxClauseCount` is 1024.\n\n## Why it didn't fail
before\nTwo reasons:\n1. ES changed how `maxClauseCount` is computed.
They've recently merged\na
[PR](elastic/elasticsearch#128293) that
made\nqueries against numeric types count three times towards
the\n`maxClauseCount` limit. They plan to revert the change in
[this\nPR](https://github.com/elastic/elasticsearch/pull/129206).\n2.
Prebuilt rule packages are growing bigger with each version,\nresulting
in a bigger number of clauses. I've tested behaviour with ES\nchange in
place on different package versions:\n- 8.17.1 (contains 1262 rule
versions) - no \"too many clauses\" error\n- 8.18.1 (contains 1356 rule
versions) - causes \"too many clauses\" error\n- 9.0.1 (also contains
1356 rule versions) - causes \"too many clauses\"\nerror\nThe precise
number of versions that start to cause errors is 1293 on
my\nlaptop.\n\nSo even if ES team rolls back their change, we still need
to make sure\nwe don't go over the limit with ever-growing prebuilt rule
package\nsizes.","sha":"482953ddc5a9e1494a3182c9cedfa4214179a297","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:Detections
and Resp","Team: SecuritySolution","Team:Detection Rule
Management","Feature:Prebuilt Detection
Rules","backport:version","v9.1.0","v8.19.0","v9.0.3","v8.18.3"],"title":"[Security
Solution] Fix \"too many clauses\" error on prebuilt rules installation
page","number":223240,"url":"https://github.com/elastic/kibana/pull/223240","mergeCommit":{"message":"[Security
Solution] Fix \"too many clauses\" error on prebuilt rules installation
page (#223240)\n\n**Resolves:
https://github.com/elastic/kibana/issues/223399**\n\n## Summary\nThis PR
fixes an error on the \"Add Elastic rules\" page. The error is\nshown
when running a local dev environment from `main` branch and going\nto
the \"Add Elastic rules\" page.\n\n<img width=\"1741\" alt=\"Screenshot
2025-06-10 at 11 28
19\"\nsrc=\"https://github.com/user-attachments/assets/f8f81f88-3749-491f-bcdb-cd51f465bda6\"\n/>\n\n##
Changes\nPR updates methods of `PrebuiltRuleAssetsClient` to split
requests to ES\ninto smaller chunks to avoid the error.\n\n##
Cause\nKibana makes a search request to ES with a filter that has too
many\nclauses, so ES rejects with an error.\n\nMore specifically,
`/prebuilt_rules/installation/_review` route handler\ncalls
`PrebuiltRuleAssetsClient.fetchAssetsByVersion` to fetch
all\ninstallable rules. To do this, we construct a request with
thousands of\nclauses in a filter. ES counts the number of clauses in a
filter and\nrejects because it's bigger than `maxClauseCount`.
`maxClauseCount`\nvalue is computed dynamically by ES and its size
depends on hardware and\navailable
resources\n([docs](https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-settings.html),\n[code](https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/search/SearchUtils.java)).\nThe
minimum value for `maxClauseCount` is 1024.\n\n## Why it didn't fail
before\nTwo reasons:\n1. ES changed how `maxClauseCount` is computed.
They've recently merged\na
[PR](elastic/elasticsearch#128293) that
made\nqueries against numeric types count three times towards
the\n`maxClauseCount` limit. They plan to revert the change in
[this\nPR](https://github.com/elastic/elasticsearch/pull/129206).\n2.
Prebuilt rule packages are growing bigger with each version,\nresulting
in a bigger number of clauses. I've tested behaviour with ES\nchange in
place on different package versions:\n- 8.17.1 (contains 1262 rule
versions) - no \"too many clauses\" error\n- 8.18.1 (contains 1356 rule
versions) - causes \"too many clauses\" error\n- 9.0.1 (also contains
1356 rule versions) - causes \"too many clauses\"\nerror\nThe precise
number of versions that start to cause errors is 1293 on
my\nlaptop.\n\nSo even if ES team rolls back their change, we still need
to make sure\nwe don't go over the limit with ever-growing prebuilt rule
package\nsizes.","sha":"482953ddc5a9e1494a3182c9cedfa4214179a297"}},"sourceBranch":"main","suggestedTargetBranches":["8.18"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/223240","number":223240,"mergeCommit":{"message":"[Security
Solution] Fix \"too many clauses\" error on prebuilt rules installation
page (#223240)\n\n**Resolves:
https://github.com/elastic/kibana/issues/223399**\n\n## Summary\nThis PR
fixes an error on the \"Add Elastic rules\" page. The error is\nshown
when running a local dev environment from `main` branch and going\nto
the \"Add Elastic rules\" page.\n\n<img width=\"1741\" alt=\"Screenshot
2025-06-10 at 11 28
19\"\nsrc=\"https://github.com/user-attachments/assets/f8f81f88-3749-491f-bcdb-cd51f465bda6\"\n/>\n\n##
Changes\nPR updates methods of `PrebuiltRuleAssetsClient` to split
requests to ES\ninto smaller chunks to avoid the error.\n\n##
Cause\nKibana makes a search request to ES with a filter that has too
many\nclauses, so ES rejects with an error.\n\nMore specifically,
`/prebuilt_rules/installation/_review` route handler\ncalls
`PrebuiltRuleAssetsClient.fetchAssetsByVersion` to fetch
all\ninstallable rules. To do this, we construct a request with
thousands of\nclauses in a filter. ES counts the number of clauses in a
filter and\nrejects because it's bigger than `maxClauseCount`.
`maxClauseCount`\nvalue is computed dynamically by ES and its size
depends on hardware and\navailable
resources\n([docs](https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-settings.html),\n[code](https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/search/SearchUtils.java)).\nThe
minimum value for `maxClauseCount` is 1024.\n\n## Why it didn't fail
before\nTwo reasons:\n1. ES changed how `maxClauseCount` is computed.
They've recently merged\na
[PR](elastic/elasticsearch#128293) that
made\nqueries against numeric types count three times towards
the\n`maxClauseCount` limit. They plan to revert the change in
[this\nPR](https://github.com/elastic/elasticsearch/pull/129206).\n2.
Prebuilt rule packages are growing bigger with each version,\nresulting
in a bigger number of clauses. I've tested behaviour with ES\nchange in
place on different package versions:\n- 8.17.1 (contains 1262 rule
versions) - no \"too many clauses\" error\n- 8.18.1 (contains 1356 rule
versions) - causes \"too many clauses\" error\n- 9.0.1 (also contains
1356 rule versions) - causes \"too many clauses\"\nerror\nThe precise
number of versions that start to cause errors is 1293 on
my\nlaptop.\n\nSo even if ES team rolls back their change, we still need
to make sure\nwe don't go over the limit with ever-growing prebuilt rule
package\nsizes.","sha":"482953ddc5a9e1494a3182c9cedfa4214179a297"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/224269","number":224269,"state":"OPEN"},{"branch":"9.0","label":"v9.0.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/224282","number":224282,"state":"OPEN"},{"branch":"8.18","label":"v8.18.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
@banderror banderror added release_note:fix and removed release_note:skip Skip the PR/issue when compiling release notes labels Jul 22, 2025
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 bug Fixes for quality problems that affect the customer experience Feature:Prebuilt Detection Rules Security Solution Prebuilt Detection Rules area release_note:fix Team:Detection Rule Management Security Detection Rule Management Team Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.18.3 v8.19.0 v9.0.3 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Security Solution] Prebuilt rules installation page shows "too_many_clauses" error
5 participants