How to Set max_result_window in Elasticsearch for Large Result Sets
To set
max_result_window in Elasticsearch, update the index settings using the PUT API with the index.max_result_window parameter. This controls the maximum number of search hits you can page through, and you must apply it per index.Syntax
The max_result_window setting is configured per index using the PUT /{index}/_settings API call. You specify the new limit inside index.max_result_window in the JSON body.
Example parts:
{index}: The name of your Elasticsearch index.index.max_result_window: The maximum number of results you want to allow for pagination.
json
PUT /my_index/_settings
{
"index" : {
"max_result_window" : 50000
}
}Example
This example increases the max_result_window to 50,000 for an index named products. This allows you to page through up to 50,000 search results instead of the default 10,000.
json
PUT /products/_settings
{
"index" : {
"max_result_window" : 50000
}
}Output
{
"acknowledged" : true
}
Common Pitfalls
Common mistakes when setting max_result_window include:
- Trying to set it globally instead of per index. It must be set on each index individually.
- Setting a very high value can cause high memory use and slow queries.
- Not refreshing the index settings after update, so the change doesn't take effect immediately.
Always test performance impact when increasing this value.
json
### Wrong: Trying to set globally (this will fail) PUT /_settings { "index" : { "max_result_window" : 50000 } } ### Right: Set per index PUT /my_index/_settings { "index" : { "max_result_window" : 50000 } }
Quick Reference
| Setting | Description | Default Value | Notes |
|---|---|---|---|
| index.max_result_window | Maximum number of search results that can be paged through | 10000 | Set per index; increasing may impact performance |
| API Endpoint | Where to set the value | PUT /{index}/_settings | Replace {index} with your index name |
| Effect | Controls max offset for from+size pagination | 10000 | Use scroll or search_after for deep pagination instead |
Key Takeaways
Set max_result_window per index using PUT /{index}/_settings with index.max_result_window.
Default max_result_window is 10,000; increase only if you need to page deeper.
High max_result_window values can cause performance and memory issues.
Use scroll or search_after APIs for efficient deep pagination instead of very large max_result_window.
Always verify changes with acknowledged response and test query performance.