关于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基础搜索(一)
相关推荐
lierenvip14 小时前
SQL 建表语句详解
java·数据库·sql
zuguangboy14 小时前
【Oracle-无效的参数绑定】DateTimeOffset映射TIMESTAMP WITH LOCAL TIME ZONE踩坑记
数据库·oracle
未来龙皇小蓝14 小时前
【MySQL-索引调优】02:单列索引
数据库·mysql·性能优化
剑锋所指,所向披靡!14 小时前
MySQL数据的增删改查
java·数据库·mysql
Villiam_AY14 小时前
一次 DNS 端口引发的代理网络和公司内网冲突问题
java·服务器·数据库
韩立学长14 小时前
Springboot奶茶加盟信息管理系统m307m786(程序、源码、数据库、调试部署方案及开发环境)系统界面展示及获取方式置于文档末尾,可供参考。
数据库·spring boot·后端
2401_8442213215 小时前
Python数据库操作:SQLAlchemy ORM指南
jvm·数据库·python
zhangyueping838515 小时前
9、MYSQL-存储过程
数据库·mysql
Arya_aa15 小时前
Mysql数据库-管理和存储数据库(开源管理系统)与JDBC操作数据库步骤,JUnit以及如何将压缩包中exe程序添加上桌面图标
数据库·mysql·junit·开源
最懒的菜鸟16 小时前
redis缓存击穿
数据库·redis·缓存