Springboot项目ES报异常query_shard_exception

详细异常信息如下:

bash 复制代码
{
  "error": {
    "root_cause": [
      {
        "type": "query_shard_exception",
        "reason": "failed to create query: {\n  \"bool\" : {\n    \"filter\" : [\n      {\n        \"term\" : {\n          \"catalogId\" : {\n            \"value\" : 225,\n            \"boost\" : 1.0\n          }\n        }\n      },\n      {\n        \"term\" : {\n          \"brandId\" : {\n            \"value\" : \"]\",\n            \"boost\" : 1.0\n          }\n        }\n      }\n    ],\n    \"adjust_pure_negative\" : true,\n    \"boost\" : 1.0\n  }\n}",
        "index_uuid": "G8KJBv5AStmJsPDg7OjoIw",
        "index": "gulimall_product"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "gulimall_product",
        "node": "eUl-GCThSO6PCxCvSjCb5w",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: {\n  \"bool\" : {\n    \"filter\" : [\n      {\n        \"term\" : {\n          \"catalogId\" : {\n            \"value\" : 225,\n            \"boost\" : 1.0\n          }\n        }\n      },\n      {\n        \"term\" : {\n          \"brandId\" : {\n            \"value\" : \"]\",\n            \"boost\" : 1.0\n          }\n        }\n      }\n    ],\n    \"adjust_pure_negative\" : true,\n    \"boost\" : 1.0\n  }\n}",
          "index_uuid": "G8KJBv5AStmJsPDg7OjoIw",
          "index": "gulimall_product",
          "caused_by": {
            "type": "number_format_exception",
            "reason": "For input string: \"]\""
          }
        }
      }
    ]
  },
  "status": 400

从caused_by找出导致异常的根本原因,For input string:\"|""。因为查询参数中传入了数组,再查看项目中构建DSL语句,终于找到异常爆发的原因了,

java 复制代码
 if(!CollectionUtils.isEmpty(params.getBrandId())){
      boolQuery.filter(QueryBuilders.termQuery("brandId",params.getBrandId()));
  }

而参数brandId是List类型,允许传入多个值,因此使用termQuery是错误的,它只能传入一个值,很明显是这里调错方法了,多个值的集合、数组,应该使用termsQuery方法,把方法调整过来就不报错了。附2个方法的传参对比:

相关推荐
麦兜*1 小时前
Spring Boot 企业级动态权限全栈深度解决方案,设计思路,代码分析
java·spring boot·后端·spring·spring cloud·性能优化·springcloud
ruan1145142 小时前
MySQL4种隔离级别
java·开发语言·mysql
Hellyc6 小时前
基于模板设计模式开发优惠券推送功能以及对过期优惠卷进行定时清理
java·数据库·设计模式·rocketmq
lifallen6 小时前
Paimon LSM Tree Compaction 策略
java·大数据·数据结构·数据库·算法·lsm-tree
hdsoft_huge6 小时前
SpringBoot 与 JPA 整合全解析:架构优势、应用场景、集成指南与最佳实践
java·spring boot·架构
百锦再7 小时前
详细解析 .NET 依赖注入的三种生命周期模式
java·开发语言·.net·di·注入·模式·依赖
程序员的世界你不懂7 小时前
基于Java+Maven+Testng+Selenium+Log4j+Allure+Jenkins搭建一个WebUI自动化框架(2)对框架加入业务逻辑层
java·selenium·maven
有没有没有重复的名字8 小时前
线程安全的单例模式与读者写者问题
java·开发语言·单例模式
张先shen9 小时前
Elasticsearch RESTful API入门:基础搜索与查询DSL
大数据·spring boot·elasticsearch·搜索引擎·全文检索·restful
慕木兮人可9 小时前
Docker部署MySQL镜像
spring boot·后端·mysql·docker·ecs服务器