关于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基础搜索(一)
相关推荐
不会就选b9 小时前
MySQL之视图
数据库·mysql
>no problem<9 小时前
基于cola5.0的基础设施层的多数据库切换方案思路
数据库·spring boot·mybatisplus·cola5.0·数据库迁移适配
OceanBase数据库官方博客9 小时前
OceanBase 赋能央国企:从发电到用电的全链路业务承载
数据库·oceanbase
金融支付架构实战指南10 小时前
支付系统 ES 实战案例:从索引创建到真实业务查询
大数据·elasticsearch·搜索引擎·支付
瀚高PG实验室10 小时前
pgsql-ogr-fdw
数据库·postgresql·瀚高数据库·highgo
IvorySQL10 小时前
PostgreSQL 技术日报 (6月5日)|PG19 Beta1 上线,PGConf.PL 2026开启征稿
数据库·postgresql·区块链
abcy07121311 小时前
pycharm python sqlalchemy mysql增删改查实例csdn
数据库·oracle
无风听海11 小时前
IndexedDB 深度指南 浏览器中的事务型对象数据库
前端·数据库
咋吃都不胖lyh12 小时前
langgraph基础示例
数据库
网管NO.112 小时前
子查询进阶|EXISTS/IN/ANY/ALL,优化查询效率
数据库·sql