# ElasticsearchException: The aggregation [my_agg] exceeded the max size of [10000]

- **ID:** `elasticsearch/aggregation-max-size-exceeded`
- **Domain:** elasticsearch
- **Category:** query_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

A terms aggregation request has a size parameter larger than the default max size limit of 10000.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| elasticsearch 7.15.0 | active | — | — |
| elasticsearch 8.8.0 | active | — | — |
| elasticsearch 8.13.0 | active | — | — |

## Workarounds

1. **Increase the max size limit dynamically: PUT _cluster/settings { "transient": { "search.max_buckets": 20000 } }** (85% success)
   ```
   Increase the max size limit dynamically: PUT _cluster/settings { "transient": { "search.max_buckets": 20000 } }
   ```
2. **Reduce the aggregation size to 10000 or lower, and use pagination with composite aggregation for larger datasets.** (90% success)
   ```
   Reduce the aggregation size to 10000 or lower, and use pagination with composite aggregation for larger datasets.
   ```
3. **Use a filtered aggregation to narrow down the result set, e.g., add a query filter before the aggregation.** (75% success)
   ```
   Use a filtered aggregation to narrow down the result set, e.g., add a query filter before the aggregation.
   ```

## Dead Ends

- **** — Size 0 is treated as unlimited, but can cause memory overflow and is deprecated in newer versions. (60% fail)
- **** — The cluster-level max size limit still applies; the error persists unless the limit is raised. (90% fail)
- **** — Composite aggregation has its own limits and may not be suitable for all use cases. (40% fail)
