# SearchPhaseExecutionException: all shards failed: [search_phase_execution_exception] Reason: Timed out after [30000ms] while waiting for search results

- **ID:** `elasticsearch/search-phase-execution-timeout`
- **Domain:** elasticsearch
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The search request timed out because one or more shards took longer than the configured timeout to respond, often due to slow queries or resource contention.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| elasticsearch 7.17 | active | — | — |
| elasticsearch 8.10 | active | — | — |
| elasticsearch 8.12 | active | — | — |

## Workarounds

1. **Increase the search timeout for specific requests: POST /my_index/_search { "timeout": "60s", "query": { "match": { "field": "value" } } }** (80% success)
   ```
   Increase the search timeout for specific requests: POST /my_index/_search { "timeout": "60s", "query": { "match": { "field": "value" } } }
   ```
2. **Optimize the query by adding index filters or reducing aggregation complexity: use 'filter' context instead of 'query' for non-scoring filters, and limit 'size' and 'aggs'.** (85% success)
   ```
   Optimize the query by adding index filters or reducing aggregation complexity: use 'filter' context instead of 'query' for non-scoring filters, and limit 'size' and 'aggs'.
   ```
3. **Use async search for long-running queries: POST /my_index/_async_search { "size": 0, "query": { "match_all": {} }, "aggs": { "my_agg": { "terms": { "field": "field", "size": 10000 } } }, "wait_for_completion_timeout": "10s" }** (90% success)
   ```
   Use async search for long-running queries: POST /my_index/_async_search { "size": 0, "query": { "match_all": {} }, "aggs": { "my_agg": { "terms": { "field": "field", "size": 10000 } } }, "wait_for_completion_timeout": "10s" }
   ```

## Dead Ends

- **** — This only delays the failure; slow queries still consume resources and may eventually cause cluster instability. (60% fail)
- **** — This changes the search semantics and returns inaccurate results, breaking application functionality. (75% fail)
- **** — Restarting does not fix the underlying slow query or resource issue; the timeout will recur after the cluster recovers. (70% fail)
