关于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基础搜索(一)
相关推荐
white-persist7 小时前
【vulhub weblogic CVE-2017-10271漏洞复现】vulhub weblogic CVE-2017-10271漏洞复现详细解析
java·运维·服务器·网络·数据库·算法·安全
sR916Mecz8 小时前
MongoDB 详解、应用场景及案例分析(AI)
数据库·mongodb
sR916Mecz8 小时前
pache Hop实战:Windows平台MySQL数据迁移的深度排错与性能调优
数据库·windows·mysql
taWSw5OjU8 小时前
MyBatis-plus进阶之映射与条件构造器
数据库·oracle·mybatis
Aktx20FNz8 小时前
iFlow CLI 完整工作流指南
大数据·elasticsearch·搜索引擎
诗人不写诗8 小时前
spring boot apm生态
java·数据库·spring boot
LaughingZhu9 小时前
Anthropic 收购 Oven 后,Claude Code 用运行时写了一篇护城河文章
大数据·人工智能·经验分享·搜索引擎·语音识别
学习3人组9 小时前
TortoiseGit冲突解决实战上机练习
大数据·elasticsearch·搜索引擎
火飞鹰10 小时前
封装MinIO为starter
java·数据库·spring boot