关于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基础搜索(一)
相关推荐
2501_9454235411 分钟前
游戏与图形界面(GUI)
jvm·数据库·python
大傻^11 分钟前
Spring AI Alibaba Agent开发:基于ChatClient的智能体构建模式
java·数据库·人工智能·后端·spring·springaialibaba
爬山算法13 分钟前
MongoDB(50)副本集中的角色有哪些?
数据库·mongodb
大傻^27 分钟前
Spring AI Alibaba 向量数据库集成:Milvus与Elasticsearch配置详解
数据库·人工智能·spring·elasticsearch·milvus·springai·springaialibaba
redsea_HR37 分钟前
红海eHR解决方案背后的底层能力
大数据·数据库·人工智能
ba_pi43 分钟前
每天写点什么2026-03-19-Doris三种存储模型
java·数据库·mysql
oem11044 分钟前
Python Web爬虫入门:使用Requests和BeautifulSoup
jvm·数据库·python
CSDN_Colinw1 小时前
Python GUI开发:Tkinter入门教程
jvm·数据库·python
Hui Baby1 小时前
TIDB分布式数据库提交设想
数据库·分布式·tidb