关于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基础搜索(一)
相关推荐
小陳参上9 分钟前
用Python创建一个Discord聊天机器人
jvm·数据库·python
changhong19861 小时前
如何在 Spring Boot 中配置数据库?
数据库·spring boot·后端
执笔画情ora4 小时前
Postgresql数据库管理-pg_xact
数据库·postgresql·oracle
南棱笑笑生4 小时前
20260310在瑞芯微原厂RK3576的Android14查看系统休眠时间
服务器·网络·数据库·rockchip
XDHCOM4 小时前
ORA-32152报错咋整啊,数据库操作遇到null number问题远程帮忙修复
服务器·数据库·oracle
专利观察员5 小时前
输配电行业创新转型实践:南宁迪**力有限公司的专利策略调整、专利检索工具采用
数据库·科技·专利·专利申请
jgyzl5 小时前
2026.3.9 Redis内存回收内存淘汰
数据库·redis·缓存
白露与泡影5 小时前
MySQL 时间类型选型避坑:timestamp 和 datetime 该怎么选?
数据库·mysql
青槿吖6 小时前
第二篇:告别XML臃肿配置!Spring注解式IOC/DI保姆级教程,从入门到真香
xml·java·开发语言·数据库·后端·sql·spring
运维 小白6 小时前
2. 部署mysql服务并监控mysql
数据库·mysql·adb