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

相关推荐
中国搜索直付通3 分钟前
避开直付通选型暗礁:二级商户的合规生存与背景甄别
java·大数据·开发语言·人工智能·游戏
leoZ23111 分钟前
Git 集成实战完全指南(六):Git 标签与版本管理
大数据·git·elasticsearch
不才不才不不才24 分钟前
Spring AI 实战(7):向量库怎么选?PgVector/Redis/Milvus 横向对比
java·人工智能·spring·ai
Qimooidea39 分钟前
祁木 CAD Translator 深度评测:从参数解析到工程交付实战
java·开发语言·人工智能·机器翻译
海兰1 小时前
【Elasticsearch】工作流自动化评估
elasticsearch·自动化·jenkins
我登哥MVP1 小时前
走进 Gang of Four 设计模式:解释器模式
java·设计模式·解释器模式
智码看视界1 小时前
Tomcat架构深度拆解:Connector和Container到底怎么配合的?
java·servlet·架构·tomcat·web服务器
浪客川1 小时前
idea 技巧 region 的使用
java·ide·intellij-idea
杨运交1 小时前
[049][Crypto模块]前后端混合加密API实战:基于Spring Boot的AES+RSA安全传输方案
spring boot·后端·安全