关于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基础搜索(一)
相关推荐
老陈头聊SEO7 分钟前
长尾关键词在提升SEO效果中的实战应用与策略探讨
其他·搜索引擎·seo优化
小尔¥8 分钟前
MySQL故障排查与优化
运维·数据库·mysql
rrrjqy12 分钟前
Redis常见问题(一)
数据库·redis·缓存
Humbunklung14 分钟前
WMO 天气代码(Code Table 4677)深度解析与应用报告
开发语言·数据库·python
道清茗23 分钟前
【MySQL知识点问答题】锁机制、索引优化与数据库恢复方法
数据库·mysql
hero.fei36 分钟前
排查redis出现报错ERR redis temporary failure
数据库·redis·缓存
JoshRen36 分钟前
springboot之集成Elasticsearch
spring boot·后端·elasticsearch
Elasticsearch41 分钟前
使用 OpenTelemetry 和 Elastic 的 ML 和 AI Ops 可观测性
elasticsearch
野犬寒鸦44 分钟前
MySQL复习记录Day01
数据库·后端
终端行者1 小时前
记录一次ES索引迁移报错:1.两边索引参数不一致2.分析器与存储属性有冲突
elasticsearch