关于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基础搜索(一)
相关推荐
叫我:松哥1 小时前
基于flask仿小米商城管理系统,使用flask开的一个商场网站
数据库·后端·python·flask
子非鱼a1 小时前
【WEB】[BJDCTF2020]Easy MD5
数据库
APItesterCris2 小时前
告别人工盯品:借助 OpenClaw 搭建商品自动监控与数据分析系统(完整实操)
大数据·数据库·数据仓库·自动化
zcn1262 小时前
exists子查询改写思考
数据库·sql·sql优化改写
betazhou2 小时前
mysql shell8.4.10+mysql 8.4.10搭建MySQL replicaset主从
数据库·mysql·ffmpeg·replicaset·mysql shell
zcmodeltech2 小时前
反应装置模型控制系统设计与实现:多设备协同联动方案
java·网络·数据库·stm32·嵌入式硬件·能源·制造
Elastic 中国社区官方博客3 小时前
从建议到修复的 4 个阶段:使用 Elastic Workflows 实现人在回路中的自动化
运维·数据库·人工智能·后端·elasticsearch·ai·自动化
北京靠谱的GEO优化机构3 小时前
海外推广:没有媒体内容,SEO就是“无米之炊“
服务器·数据库·媒体
2601_962071573 小时前
数据库系统架构与DBMS功能探微:现代信息时代数据管理的关键
java·开发语言·数据库
circuitsosk3 小时前
从零搭建行业知识平台:向量库+图数据库+传统关系库的多模检索统一层设计
数据库·python·oracle·向量数据库·rag·多模检索