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个方法的传参对比:

相关推荐
小小小米粒几秒前
线程池创建模版
java
TE-茶叶蛋3 分钟前
`@interface` 解析
java
摇滚侠4 分钟前
Java 项目教程《黑马商城》微服务拆分 05 - 10
java·开发语言·微服务
PPPPickup7 分钟前
实习日志5.7
java
_Evan_Yao7 分钟前
return 的迷途:try-catch-finally 中 return 的诡异顺序与 Spring 事务暗坑
java·后端·spring·mybatis
薛定谔的猫喵喵8 分钟前
Spring Boot Jar包修改配置文件和Class中硬编码IP的完整指南
java·spring boot·反编译·class
Seven9712 分钟前
Tomcat Request请求处理过程:Connector
java
Mr数据杨12 分钟前
【Codex】搭建教学中心数据工作台统筹教案与课件资源
java·开发语言·django·codex·项目开发
海兰18 分钟前
【第35篇】文本摘要微服务
人工智能·spring boot·微服务·架构·spring ai
未来龙皇小蓝19 分钟前
SpringBoot API日志系统设计-02:线程池异步化与RabbitMQ解耦
数据库·spring boot·后端·性能优化·rabbitmq·java-rabbitmq