elasticsearch TooManyClauses问题

在使用 es-sql 执行 sql 语句时,使用了 in 的子查询

select name, hign from students where name not in ( select name from students where age > 16)

当子查询中的语句结果超过1024时,发现会将部分不满足条件的结果查出来,
es-sql 也是将sql转化为 DSL 语言处理,其转化后使用bool查询
使用 limit 限制

select name, hign from students where name not in ( select name from students where age > 16 limit 2000)

报错:

"caused_by":{"type":"too_many_clauses","reason":"maxClauseCount is set to 1024"}}}],
"caused_by":{"type":"query_shard_exception","reason":"failed to create query:

查询文档:
https://www.elastic.co/guide/en/elasticsearch/reference/6.7/search-settings.html

The following expert setting can be set to manage global search limits.

indices.query.bool.max_clause_count
Defaults to 1024.
This setting limits the number of clauses a Lucene BooleanQuery can have. The default of 1024 is quite high and should normally be sufficient. This limit does not only affect Elasticsearchs bool query, but many other queries are rewritten to Lucene’s BooleanQuery internally. The limit is in place to prevent searches from becoming to large and taking up too much CPU and memory. In case you consider to increase this setting, make sure you exhausted all other options to avoid having to do this. Higher values can lead to performance degradations and memory issues, especially in clusters with a high load or few resources.

意思大概就是bool默认限制1024,太大会消耗太多的CPU资源和内存。
本来想在线修改一下这个配置,发现其实 global 全局变量,修改它,需要修改 elasticsearch.yml 文件,并且需要重启 es 集群,所以放弃了这种方式。
改为在代码逻辑中处理。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值