Springboot项目ES报异常query_shard_exception

作者 : admin 本文共1273个字,预计阅读时间需要4分钟 发布时间: 2024-06-15 共1人阅读

详细异常信息如下:

{
  "error": {
    "root_cause": [
      {
        "type": "query_shard_exception",
        "reason": "failed to create query: {
  \"bool\" : {
    \"filter\" : [
      {
        \"term\" : {
          \"catalogId\" : {
            \"value\" : 225,
            \"boost\" : 1.0
          }
        }
      },
      {
        \"term\" : {
          \"brandId\" : {
            \"value\" : \"]\",
            \"boost\" : 1.0
          }
        }
      }
    ],
    \"adjust_pure_negative\" : true,
    \"boost\" : 1.0
  }
}",
        "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: {
  \"bool\" : {
    \"filter\" : [
      {
        \"term\" : {
          \"catalogId\" : {
            \"value\" : 225,
            \"boost\" : 1.0
          }
        }
      },
      {
        \"term\" : {
          \"brandId\" : {
            \"value\" : \"]\",
            \"boost\" : 1.0
          }
        }
      }
    ],
    \"adjust_pure_negative\" : true,
    \"boost\" : 1.0
  }
}",
          "index_uuid": "G8KJBv5AStmJsPDg7OjoIw",
          "index": "gulimall_product",
          "caused_by": {
            "type": "number_format_exception",
            "reason": "For input string: \"]\""
          }
        }
      }
    ]
  },
  "status": 400

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

 if(!CollectionUtils.isEmpty(params.getBrandId())){
      boolQuery.filter(QueryBuilders.termQuery("brandId",params.getBrandId()));
  }

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

Springboot项目ES报异常query_shard_exception插图

Springboot项目ES报异常query_shard_exception插图(1)

本站无任何商业行为
个人在线分享 » Springboot项目ES报异常query_shard_exception
E-->