关于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基础搜索(一)
相关推荐
Antoine-zxt21 小时前
MySQL宕机日志迷局破解指南:从前台启动到精准排错
数据库·mysql·adb
松涛和鸣21 小时前
DAY47 FrameBuffer
c语言·数据库·单片机·sqlite·html
阳宗德21 小时前
基于CentOS Linux release 7.1实现了Oracle Database 11g R2 企业版容器化运行
linux·数据库·docker·oracle·centos
草莓熊Lotso21 小时前
脉脉独家【AI创作者xAMA】| 多维价值与深远影响
运维·服务器·数据库·人工智能·脉脉
会飞的胖达喵21 小时前
Redis 协议详解与 Telnet 直接连redis
数据库·redis·redis协议
DKunYu1 天前
3.远程操作
大数据·git·elasticsearch·搜索引擎·gitee
言之。1 天前
DDIA第四章 数据库存储引擎面试问题集
数据库·面试·职场和发展·ddia
wangbing11251 天前
redis的存储问题
数据库·redis·缓存
剑来.1 天前
一次完整的 MySQL 性能问题排查思路(线上实战总结)
数据库·mysql·oracle
2301_800256111 天前
【数据库】查找距离最近的电影院 pgSQL 存储过程片段
大数据·数据库·excel