关于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基础搜索(一)
相关推荐
落笔画忧愁e3 分钟前
FastGPT快速将消息发送至飞书
服务器·数据库·飞书
Σίσυφος190017 分钟前
halcon 条形码、二维码识别、opencv识别
前端·数据库
小刘|1 小时前
深入理解 SQL 注入漏洞及解决方案
数据库·sql
天上掉下来个程小白2 小时前
案例-14.文件上传-简介
数据库·spring boot·后端·mybatis·状态模式
risc1234562 小时前
【Elasticsearch】Search Templates(搜索模板)
elasticsearch
哆木2 小时前
排查生产sql查询缓慢
数据库·sql·mysql
橘子师兄3 小时前
分页功能组件开发
数据库·python·django
book01213 小时前
MySql数据库运维学习笔记
运维·数据库·mysql
纠结哥_Shrek3 小时前
Oracle和Mysql的区别
数据库·mysql·oracle
极客先躯3 小时前
说说高级java每日一道面试题-2025年2月13日-数据库篇-请说说 MySQL 数据库的锁 ?
java·数据库·mysql·数据库的锁·模式分·粒度分·属性分