You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Security Solution] Fix "too many clauses" error on prebuilt rules installation page (#223240)
**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.
<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.
Copy file name to clipboardExpand all lines: x-pack/solutions/security/plugins/security_solution/server/lib/detection_engine/prebuilt_rules/logic/rule_assets/prebuilt_rule_assets_client.ts
* @param {T[]} options.items - Array of items to create filters for.
199
+
* @param {(item: T) => string} options.mapperFn - A function that maps an item to a filter string.
200
+
* @param {number} options.clausesPerItem - Number of Elasticsearch clauses generated per item. Determined empirically by converting a KQL filter into a Query DSL query.
201
+
* More complex filters will result in more clauses. Info about clauses in docs: https://www.elastic.co/docs/explore-analyze/query-filter/languages/querydsl#query-dsl
0 commit comments