关于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基础搜索(一)
相关推荐
小嵌同学8 分钟前
Linux:malloc背后的实现细节
大数据·linux·数据库
R瑾安23 分钟前
mysql安装(压缩包方式8.0及以上)
数据库·mysql
代码的余温28 分钟前
MySQL Cluster核心优缺点
数据库·mysql
Mr.Entropy2 小时前
请求超过Spring线程池的最大线程(处理逻辑)
数据库·sql·spring
GBASE2 小时前
“G”术时刻:南大通用GBase 8c数据库权限管理场景实践(二)
数据库
AAA修煤气灶刘哥2 小时前
ES 聚合爽到飞起!从分桶到 Java 实操,再也不用翻烂文档
后端·elasticsearch·面试
Elasticsearch2 小时前
Elastic Observability 中 Discover 的跟踪,用于深入的应用洞察
elasticsearch
Elasticsearch3 小时前
使用 cloud-native Elasticsearch 与 ECK 运行
elasticsearch
wearegogog1233 小时前
MySQL中实施排序(sorting)及分组(grouping)操作
数据库·mysql
2301_803554523 小时前
MySQL 主从读写分离架构
数据库·mysql·架构