olivere / elastic

Deprecated: Use the official Elasticsearch client for Go at https://github.com/elastic/go-elasticsearch
https://olivere.github.io/elastic/
MIT License
7.42k stars 1.15k forks source link

how to get root cause with 400 error #1662

Closed govida closed 1 year ago

govida commented 1 year ago

Which version of Elastic are you using?

elastic.v7 (for Elasticsearch 7.x)

Please describe the expected behavior

I want root cause with 400 error like

{
  "error" : {
    "root_cause" : [
      {
        "type" : "too_many_clauses",
        "reason" : "too_many_clauses: maxClauseCount is set to 1024"
      },
      {
        "type" : "too_many_clauses",
        "reason" : "too_many_clauses: maxClauseCount is set to 1024"
      },
      {
        "type" : "too_many_clauses",
        "reason" : "too_many_clauses: maxClauseCount is set to 1024"
      },
      {
        "type" : "too_many_clauses",
        "reason" : "too_many_clauses: maxClauseCount is set to 1024"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "article_202211",
        "node" : "9LxMXvdkRAWwUP0lFlApcg",
        "reason" : {
          "type" : "query_shard_exception",
          "reason" : "failed to create query: maxClauseCount is set to 1024",
          "index_uuid" : "kf6xAESkSL-A9o3agqOi8A",
          "index" : "article_202211",
          "caused_by" : {
            "type" : "too_many_clauses",
            "reason" : "too_many_clauses: maxClauseCount is set to 1024"
          }
        }
      }

    ],
    "caused_by" : {
      "type" : "too_many_clauses",
      "reason" : "too_many_clauses: maxClauseCount is set to 1024"
    }
  },
  "status" : 400
}

Please describe the actual behavior

But I only got the elastic: Error 400 (Bad Request): all shards failed [type=search_phase_execution_exception] without the root cause, which makes me confused that I can't locate this root error immediately since there are so many errors with 400

olivere commented 1 year ago

You can do a type switch and get this structure back.

But you should really switch to the official Go client ASAP.