超时/取消长时间运行的Elasticsearch查询

huangapple go评论65阅读模式
英文:

Timeout/Cancel long running elasticsearch query

问题

如何有效设置 Elasticsearch 中昂贵查询的超时/取消?

ES 集群的数据存储容量约为 100T,其中已使用了 60T。分片大小为 20G。
search.default_search_timeoutsearch.cancel_after_time_interval 已设置为 1 秒,但未生效。

英文:

What is a good way to timeout/cancel a expensive query in elasticsearch?

ES Cluster' data storage capacity is about 100T off which 60T is used. Shard size is 20G.
search.default_search_timeout and search.cancel_after_time_interval were set to 1sec and didn't work.

答案1

得分: 1

The search timeout can be configurable at query time and also it can be configurable via cluster settings to apply all your searches.

GET test_index/_search
{
  "timeout": "60s",
  "query": {},
  "aggs": {}
}
PUT /_cluster/settings
{
  "persistent": {
    "search.default_search_timeout": "60s"
  }
}

Note: The query timeout is not guaranteed. In some cases (especially in very large indices) the timeout operation may fail. To set a cluster-wide default timeout for all search requests, configure search.default_search_timeout using the cluster settings API. This global timeout duration is used if no timeout argument is passed in the request. If the global search timeout expires before the search request finishes, the request is canceled using task cancellation. The search.default_search_timeout setting defaults to -1 (no timeout).

please note that the timeout is per shard not per request

As you experienced it's not guaranteed the timeout. To protect your cluster and drop heavy queries you need to use an external application. I recommend you check the Search gateway.

超时/取消长时间运行的Elasticsearch查询

英文:

The search timeout can be configurable at query time and also it can be configurable via cluster settings to apply all your searches.

GET test_index/_search
{
  "timeout": "60s", 
  "query": {},
  "aggs": {}
}

PUT /_cluster/settings
{
  "persistent": {
    "search.default_search_timeout": "60s"
  }
}

Note: The query timeout is not guaranteed. In some cases (especially in very large indices) the timeout operation may fail.
To set a cluster-wide default timeout for all search requests, configure search.default_search_timeout using the cluster settings API. This global timeout duration is used if no timeout argument is passed in the request. If the global search timeout expires before the search request finishes, the request is cancelled using task cancellation. The search.default_search_timeout setting defaults to -1 (no timeout).

> please note that the timeout is per shard not per request

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-your-data.html

As you experienced it's not guaranteed the timeout. To protect your cluster and drop heavy queries you need to use an external application. I recommend you check the Search gateway.

https://opster.com/opensearch-search-gateway/

超时/取消长时间运行的Elasticsearch查询

huangapple
  • 本文由 发表于 2023年3月9日 16:39:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75682149.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定