1.概述
当我们使用Elasticsearch查询数据时,如果数据量非常大时
,会命中大量分片中的大量数据
,可能会造成集群内存异常
,此时可以通过一个高级参数batched_reduce_size
进行控制。使用方法如下:
GET user_order/_search?q=user:kimchy&batched_reduce_size=256
或者:
POST /user_order/_search
{
"query" : {
"term" : { "user" : "kimchy"}
"batched_reduce_size":256
}
}
关于batched_reduce_size参数,官网英文的解释:
(Optional, integer) The number of shard results that should be reduced at once on the coordinating node. This value should be used as a protection mechanism to reduce the memory overhead per search request if the potential number of shards in the request can be large.
如果对Elasticsearch的原理没有一定的理解,这段英文理解起来有点困难。batched_reduce_size具体的用途和含义如下:
此参数用来限制协调节点(也就是接受请求的节点)一次(批)处理的分片数量,如果命中的分片数量大于此参数值,则会分批执行,默认值为512
。如果请求中潜在的分片数量很大,则应将此值用作保护机制,以减少每个搜索请求的内存开销。
比如做一个count处理,10亿条数据,如果10亿条数据都汇总到一台机器做计算,那么肯定会OOM,因此,假设每个分片每次只来1万条数据,计算完后,再次拉取数据,那么逐渐达到10亿条数据,那么就能保证机器内存在一定范围内,不至于OOM.
原文链接:https://blog.csdn.net/zhaojianting/article/details/103276326