关于elasticsearch的terms查询超过最大terms数

当我使用es的terms查询时,报错了这段内容。

python 复制代码
failed to create query: The number of terms [80306] used in the Terms
Query request has exceeded the allowed maximum of [65536]. This
maximum can be set by changing the [index.max_terms_count] index level
setting.

根据资料,这是es对terms的数量限制。最高限制为65536,。

要解决这个问题,我研究了两种方法:

  1. 改变最大terms数量
powershell 复制代码
curl --location --request PUT 'xxxxx/_settings' \
--header 'User-Agent: Apipost client Runtime/+https://www.apipost.cn/' \
--header 'Content-Type: application/json' \
--data '{
  "index.max_terms_count": 262144
}'
  1. 将单个terms分为多个terms,按照max_terms_count的数量,将terms的值数组切成多个数组,通过should的方式拼起来进行查询。

总结:

目前我用的这两种方法都可以实现同样的效果,当前我使用的数组长度大约是8w个,在查询速度上两个的速度基本相同。

参考资料:

  1. Terms query
  2. Elasticsearch Query DSL之Term level queries
  3. 第三章 Elasticsearch基础搜索(一)
相关推荐
@forever@1 小时前
【MySQL】数据库基础、架构与存储引擎详解
数据库·mysql·架构
轩轩曲觞阁2 小时前
MySQL基础——数据类型
数据库·mysql
jnrjian2 小时前
Oracle 19C LogMiner 分析 Supplemental Log Groups
数据库·oracle
小小测试开发3 小时前
rsync 源路径少一个斜杠,--delete 删的就不是你以为的那一层
java·前端·数据库·人工智能
小敬爱吃饭4 小时前
PgHero轻量PostgreSQL监控:Docker部署、连接统计与执行计划
数据库·docker·postgresql
2401_891409264 小时前
期权全量合约历史数据:分钟/Tick/日级/L2五档字段清单
数据库
海宇服务5 小时前
零信任架构实战:基于海宇企业司法涉诉构建自动化分包商准入合规审查网关
数据库·人工智能·架构·自动化
岳涛_daemon5 小时前
数值照旧填、请求没报错,ES 9.3 把 max_size 换成按主分片算,索引要更大才滚动
elasticsearch
W_son5 小时前
数据库归档模式开启与备份作业配置实战
数据库·oracle·达梦数据库
郝学胜-神的一滴6 小时前
Effective Python 条款47:吃透惰性属性
大数据·开发语言·数据库·人工智能·python·算法·oracle