关于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基础搜索(一)
相关推荐
CoderYanger4 小时前
Java EE 进阶:9.MyBatis 操作数据库(进阶)(第八弹):MyBatis Generator
java·数据库·spring boot·spring·java-ee·tomcat·mybatis
MSTcheng.5 小时前
【MySQL】MySQL数据库——表的操作
数据库·mysql·adb
2601_967979126 小时前
图书恐惧症者的福音,Python官方文档使用指南
搜索引擎·基础语法·快速搜索·使用指南·python官方文档
Yeats_Liao6 小时前
物联网平台MongoDB实战|(一)为什么选择MongoDB
数据库·物联网·mongodb
鹤落晴春6 小时前
MySQL日志梳理
运维·数据库·mysql
五彩小白7 小时前
Redis的过期删除和内存淘汰机制
数据库·redis·缓存
学长毕设7 小时前
基于SpringBoot 博物馆文物租赁及修复管理系统-附源码
大数据·数据库·spring boot
apcipot_rain8 小时前
C++转Java日记(14)
数据库
龙腾AI白云11 小时前
数字孪生与计算机视觉:让机器看懂现场
大数据·数据库·机器学习·知识图谱·pygame
千寻技术帮12 小时前
基于Spring Boot+Vue的农产品销售管理系统(源码+文档+数据库,附部署教程)
java·数据库·spring boot·后端·mysql·vue