The `search.default_search_timeout` setting in Elasticsearch controls the default timeout for search requests. It defines the maximum amount of time a search operation can take before it is terminated and returns partial results.
- Default value: No default timeout (-1)
- Possible values: Time value (e.g., 30s, 1m) or -1 for no timeout
- Recommendation: Set a reasonable timeout based on your use case and cluster performance
This setting applies a global default timeout to all search requests that don't specify their own timeout. When a search reaches this timeout, Elasticsearch will return the results collected up to that point, potentially providing partial or incomplete results.
Example
To set the default search timeout to 30 seconds, you can change the following dynamic setting via the /_cluster/settings
API:
PUT _cluster/settings
{
"persistent": {
"search.default_search_timeout": "30s"
}
}
This setting is also available to be changed via elasticsearch.yml
although this will require a restart and is not recommended.
You might want to change this setting if you're experiencing long-running queries that impact cluster performance. By setting a timeout, you can prevent resource-intensive searches from running indefinitely.
Effect of change: Searches that exceed the timeout will return partial results, potentially improving overall cluster responsiveness but at the cost of result completeness.
Common Issues and Misuses
- Setting the timeout too low can lead to frequent partial results, affecting the quality of search results
- Setting the timeout too high or not setting it at all can allow resource-intensive queries to impact cluster performance
- Relying solely on this global setting instead of also using request-level timeouts for critical operations
Do's and Don'ts
Do's:
- Set a reasonable timeout based on your typical query performance and requirements
- Monitor and adjust the timeout based on cluster performance and user needs
- Use request-level timeouts for specific queries that may need different timeout values
Don'ts:
- Don't set the timeout too low, as it may lead to unnecessary partial results
- Don't rely solely on this global setting for all timeout management
- Don't ignore this setting, as it can help prevent runaway queries
Frequently Asked Questions
Q: How does search.default_search_timeout differ from request-level timeouts?
A: The `search.default_search_timeout` is a cluster-wide setting that applies to all search requests by default, while request-level timeouts are specified in individual search requests and take precedence over the default timeout.
Q: What happens when a search hits the timeout?
A: When a search reaches the timeout, Elasticsearch terminates the search operation and returns the partial results collected up to that point, along with a flag indicating that the results are partial.
Q: Can I disable the default search timeout?
A: Yes, you can disable the default search timeout by setting `search.default_search_timeout` to -1, which means no timeout will be applied unless specified at the request level.
Q: How can I determine the optimal timeout value for my cluster?
A: Monitor your typical search performance, analyze slow logs, and consider your use case requirements. Start with a conservative value and adjust based on observed behavior and user feedback.
Q: Does this setting affect all types of searches in Elasticsearch?
A: This setting applies to most search operations, including queries, aggregations, and scroll searches. However, some specialized operations may have their own timeout mechanisms.