关于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基础搜索(一)
相关推荐
玄同7656 分钟前
数据库全解析:从关系型到向量数据库,LLM 开发中的选型指南
数据库·人工智能·知识图谱·milvus·知识库·向量数据库·rag
枫叶丹414 分钟前
时序数据库选型指南:在大数据浪潮中把握未来,为何Apache IoTDB值得关注?
大数据·数据库·apache·时序数据库·iotdb
小虾米vivian17 分钟前
达梦使用dmfldr和外部表导入txt数据(windows环境)
java·服务器·数据库
1104.北光c°19 分钟前
【黑马点评项目笔记 | 商户查询缓存篇】基于Redis解决缓存穿透、雪崩、击穿三剑客
java·开发语言·数据库·redis·笔记·spring·缓存
历程里程碑20 分钟前
Linux19 实现shell基本功能
linux·运维·服务器·算法·elasticsearch·搜索引擎·哈希算法
数据知道20 分钟前
PostgreSQL 核心原理:一文掌握数据库的热数据缓存池(共享缓冲区)
数据库·缓存·postgresql
·云扬·29 分钟前
MongoDB高可用方案详解:副本集与分片集群
数据库·mongodb
無森~32 分钟前
HBase实战:通话记录分析
大数据·数据库·hbase
2501_9419820533 分钟前
从孤岛到闭环:如何将企微 RPA 自动化能力无缝接入业务工作流?
数据库
ALex_zry33 分钟前
Redis Cluster 故障转移与高可用实践
数据库·redis·wpf