elasticsearch
resource_error
ai_generated
true
SearchContextTooLargeException: search context size exceeds limit
ID: elasticsearch/search-context-too-large
78%Fix Rate
82%Confidence
1Evidence
2024-03-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| elasticsearch 8.11 | active | — | — | — |
| elasticsearch 8.12 | active | — | — | — |
| elasticsearch 7.17 | active | — | — | — |
| opensearch 2.10 | active | — | — | — |
Root Cause
The search request tries to load too many documents or fields into memory, exceeding the search context memory limit.
generic中文
搜索请求尝试加载过多文档或字段到内存,超出搜索上下文内存限制。
Official Documentation
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-settings.html#search-settings-max-search-context-sizeWorkarounds
-
85% success Reduce the search request size by using smaller from/size or using search_after for pagination. Example: POST /my_index/_search { "size": 100, "search_after": [12345, "abc"] }
Reduce the search request size by using smaller from/size or using search_after for pagination. Example: POST /my_index/_search { "size": 100, "search_after": [12345, "abc"] } -
75% success Increase the search context size limit dynamically: PUT _cluster/settings { "persistent": { "search.max_search_context_size": "10mb" } }
Increase the search context size limit dynamically: PUT _cluster/settings { "persistent": { "search.max_search_context_size": "10mb" } } -
80% success Use source filtering to return only needed fields: POST /my_index/_search { "_source": ["field1", "field2"], "size": 1000 }
Use source filtering to return only needed fields: POST /my_index/_search { "_source": ["field1", "field2"], "size": 1000 }
中文步骤
通过使用较小的from/size或search_after分页来减少搜索请求大小。
动态增加搜索上下文大小限制。
使用source filtering只返回必要字段。
Dead Ends
Common approaches that don't work:
-
85% fail
This setting controls aggregation buckets, not search context memory; no effect on this error.
-
50% fail
Search context size limit is separate from heap; heap increase may help indirectly but is not the direct fix.
-
70% fail
Scroll API also creates search contexts; large size worsens the problem.