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

相关推荐
Q_970956394 分钟前
java+vue+SpringBoo校园失物招领网站(程序+数据库+报告+部署教程+答辩指导)
java·数据库·vue.js
仰望星空@脚踏实地9 分钟前
Spring Boot Web 服务单元测试设计指南
spring boot·后端·单元测试
Wyc7240912 分钟前
Maven
java·数据库·maven
程序猿小D15 分钟前
[附源码+数据库+毕业论文]基于Spring+MyBatis+MySQL+Maven+jsp实现的电影小说网站管理系统,推荐!
java·数据库·mysql·spring·毕业设计·ssm框架·电影小说网站
飞询25 分钟前
Docker 安装 Elasticsearch 9
elasticsearch·docker
木头没有瓜1 小时前
idea离线安装插件
java·ide·intellij-idea
G皮T1 小时前
【Elasticsearch】检索高亮
大数据·elasticsearch·搜索引擎·全文检索·kibana·检索·高亮
一勺菠萝丶2 小时前
Spring Boot + MyBatis/MyBatis Plus:XML中循环处理List参数的终极指南
xml·spring boot·mybatis
llwszx2 小时前
Spring中DelayQueue深度解析:从原理到实战(附结构图解析)
java·后端·spring·delayqueue·延迟任务
述雾学java2 小时前
Spring Cloud Feign 整合 Sentinel 实现服务降级与熔断保护
java·spring cloud·sentinel