# ElasticsearchException：聚合[my_agg]超过了最大大小[10000]

- **ID:** `elasticsearch/aggregation-max-size-exceeded`
- **领域:** elasticsearch
- **类别:** query_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

terms聚合请求的size参数超过了默认的最大大小限制10000。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| elasticsearch 7.15.0 | active | — | — |
| elasticsearch 8.8.0 | active | — | — |
| elasticsearch 8.13.0 | active | — | — |

## 解决方案

1. ```
   动态增加最大大小限制：PUT _cluster/settings { "transient": { "search.max_buckets": 20000 } }
   ```
2. ```
   将聚合size减少到10000或更少，并对更大数据集使用composite聚合进行分页。
   ```
3. ```
   使用过滤聚合缩小结果集，例如在聚合前添加查询过滤器。
   ```

## 无效尝试

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