关于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基础搜索(一)
相关推荐
懒鸟一枚7 分钟前
为什么 useradd -rs /bin/false service 创建的用户无法用 su 切换?
linux·服务器·数据库
爱喝热水的呀哈喽15 分钟前
hypermesh两个网格参数解析
服务器·数据库·mysql
IvorySQL1 小时前
PG 技术日报|2026-07-03
数据库·postgresql·开源
长孙豪翔1 小时前
引发事件的问题
java·linux·数据库
吴声子夜歌1 小时前
SQL进阶——HAVING子句
数据库·sql
偏爱自由 !1 小时前
5:IDEA中git的使用--git fetch 和 git pull 和解决冲突
git·elasticsearch·intellij-idea
无小道2 小时前
Redis——哨兵
数据库·redis·缓存·哨兵
agent8972 小时前
Elasticsearch 慢查询排查:从 Mapping、分片、分页到聚合优化
大数据·elasticsearch·django
闪电悠米2 小时前
黑马点评-Redis Set-实现关注、取关和共同关注
数据库·redis·缓存
爱奥尼欧2 小时前
轻量级可扩展日志框架-异步日志与系统集成
开发语言·数据库·c++·学习