关于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基础搜索(一)
相关推荐
卓怡学长21 小时前
m280本科生导师指导平台
java·数据库·spring·tomcat·maven·intellij-idea
大尚来也21 小时前
Serverless架构深度解析:适用场景、核心局限与破局之道
数据库
Wave84521 小时前
非阻塞按键(单击,双击,长按)
数据库
2401_831824961 天前
为你的Python脚本添加图形界面(GUI)
jvm·数据库·python
久违的太阳1 天前
记录一次ORACLE RAC安装PSU补丁步骤
数据库·oracle
2401_879693871 天前
用Pygame开发你的第一个小游戏
jvm·数据库·python
xushichao19891 天前
实战:用OpenCV和Python进行人脸识别
jvm·数据库·python
sthnyph1 天前
初识MySQL · 库的操作
数据库·mysql
原来是猿1 天前
MySQL【视图】
数据库·mysql
2401_873587821 天前
MySQL——事务管理
数据库·mysql