- 說明:在做es的聚合查詢時,當數據基數非常大,或者查詢語句不合理會導致es的查詢很吃力,甚至出現以下錯誤。但有時候確實需要這么查詢,這個時候需要修改max_buckets的閾值。
{ "error": { "root_cause": [], "type": "search_phase_execution_exception", "reason": "", "phase": "fetch", "grouped": true, "failed_shards": [], "caused_by": { "type": "too_many_buckets_exception", "reason": "Trying to create too many buckets. Must be less than or equal to: [65535] but was [2191545]. This limit can be set by changing the [search.max_buckets] cluster level setting.", "max_buckets": 65535 } }, "status": 503 }
- 通過 GET /_cluster/settings 可以查看max_buckets的閾值
{ "persistent" : { "search" : { "max_buckets" : "10000" }, "xpack" : { "monitoring" : { "collection" : { "enabled" : "true" } } } }, "transient" : { "search" : { "max_buckets" : "10000" } } }
- 修改方案:通過修改persistent和transient來配置max_buckets的值。
PUT /_cluster/settings { "persistent": { "search.max_buckets": 1000000 } } PUT /_cluster/settings { "transient": { "search.max_buckets": 1000000 } }