# SearchContextTooLargeException: 搜索上下文大小超出限制

- **ID:** `elasticsearch/search-context-too-large`
- **领域:** elasticsearch
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 78%

## 根因

搜索请求尝试加载过多文档或字段到内存，超出搜索上下文内存限制。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| elasticsearch 8.11 | active | — | — |
| elasticsearch 8.12 | active | — | — |
| elasticsearch 7.17 | active | — | — |
| opensearch 2.10 | active | — | — |

## 解决方案

1. ```
   通过使用较小的from/size或search_after分页来减少搜索请求大小。
   ```
2. ```
   动态增加搜索上下文大小限制。
   ```
3. ```
   使用source filtering只返回必要字段。
   ```

## 无效尝试

- **** — This setting controls aggregation buckets, not search context memory; no effect on this error. (85% 失败率)
- **** — Search context size limit is separate from heap; heap increase may help indirectly but is not the direct fix. (50% 失败率)
- **** — Scroll API also creates search contexts; large size worsens the problem. (70% 失败率)
