关于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基础搜索(一)
相关推荐
爱学习的小可爱卢2 小时前
数据库MySQL——MySQL 可重复读隔离级别:Read View 底层原理与幻读问题深度剖析(面试必知)
数据库·mysql
lifewange2 小时前
数据库索引里面的游标是什么?
数据库·oracle
PhDTool3 小时前
计算机化系统验证(CSV)的前世今生
数据库·安全·全文检索
banpu3 小时前
Spring相关
数据库·spring·sqlserver
老年DBA3 小时前
Ora2Pg 迁移Oracle至 PostgreSQL 之实战指南
数据库·postgresql·oracle
我是苏苏3 小时前
MSSQL04: SQLserver的用户权限管理
数据库
l1t3 小时前
达梦数据库和Oracle兼容性和性能比较
数据库·sql·oracle·达梦
lkbhua莱克瓦243 小时前
基础-事务
开发语言·数据库·笔记·mysql·事务
G皮T3 小时前
【Elasticsearch】查询性能调优(三):track_total_hits 和 terminate_after 可能的冲突
大数据·elasticsearch·搜索引擎·全文检索·索引·性能·opensearch
weixin_436525073 小时前
NestJS-TypeORM QueryBuilder 常用 SQL 写法
java·数据库·sql