关于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基础搜索(一)
相关推荐
晋阳十二夜5 小时前
【压力测试之_Jmeter链接Oracle数据库链接】
数据库·oracle·压力测试
GISer_Jing5 小时前
Git协作开发:feature分支、拉取最新并合并
大数据·git·elasticsearch
GDAL6 小时前
Node.js v22.5+ 官方 SQLite 模块全解析:从入门到实战
数据库·sqlite·node.js
DCTANT7 小时前
【原创】国产化适配-全量迁移MySQL数据到OpenGauss数据库
java·数据库·spring boot·mysql·opengauss
AI、少年郎9 小时前
Oracle 进阶语法实战:从多维分析到数据清洗的深度应用(第四课)
数据库·oracle
赤橙红的黄9 小时前
自定义线程池-实现任务0丢失的处理策略
数据库·spring
DataGear10 小时前
如何在DataGear 5.4.1 中快速制作SQL服务端分页的数据表格看板
javascript·数据库·sql·信息可视化·数据分析·echarts·数据可视化
weixin_4383354010 小时前
分布式锁实现方式:基于Redis的分布式锁实现(Spring Boot + Redis)
数据库·redis·分布式
码不停蹄的玄黓10 小时前
MySQL Undo Log 深度解析:事务回滚与MVCC的核心功臣
数据库·mysql·undo log·回滚日志
Qdgr_10 小时前
价值实证:数字化转型标杆案例深度解析
大数据·数据库·人工智能