ES查询的数量限制问题

时间:2025-02-13 17:09:05

ES查询的数量限制问题

1、最大返回数量
ES 默认最大返回10000条数据,当超过时,可以使用scroll进行查询(推荐),或者配置最大返回数量,否则报错:

“reason”: “Result window is too large, from + size must be less than
or equal to: [10000] but was [10001]. See the scroll api for a more
efficient way to request large data sets. This limit can be set by
changing the [index.max_result_window] index level setting.”

配置最大返回数量

PUT /indexName/_settings
{"max_result_window":"10000000"}

2、最大聚合桶数
ES 针对聚合做了性能优化,默认不允许聚合数据过大(65535),如果聚合体返回数据过大,报错:

{“error”:{“root_cause”:[{“type”:“too_many_buckets_exception”,“reason”:“Trying
to create too many buckets. Must be less than or equal to: [10000] but
was [10001]. This limit can be set by changing the
[search.max_buckets] cluster level
setting.”,“max_buckets”:10000}],“type”:“search_phase_execution_exception”,“reason”:“all
shards
failed”,“phase”:“query”,“grouped”:true,“failed_shards”:[{“shard”:0,“index”:“recommend”,“node”:“FJazr4BeSqGp5x8hS0UDxw”,“reason”:{“type”:“too_many_buckets_exception”,“reason”:“Trying
to create too many buckets. Must be less than or equal to: [10000] but
was [10001]. This limit can be set by changing the
[search.max_buckets] cluster level
setting.”,“max_buckets”:10000}}]},“status”:503}

配置最大桶数

PUT /_cluster/settings
{"persistent": {"search.max_buckets": 1000000}}