mattbaird / elastigo

A Go (golang) based Elasticsearch client library.
Apache License 2.0
943 stars 241 forks source link

Unmarshal error of parsing shards failures in SearchResult #291

Open nodestory opened 7 years ago

nodestory commented 7 years ago

The field ShardStatus of SearchResult contains the field Failure which is defined as follows:

type Failure struct {
    Index  string    `json:"index"`
    Shard  StatusInt `json:"shard"`
    Reason string    `json:"reason"`
}

But actually I got the failure in the response like this when scrolling the results:

{
    "shard": -1,
    "index": null,
    "reason": {
      "type": "es_rejected_execution_exception",
      "reason": "..."
    }
}

So every time if some shards fail, I'll get an error json: cannot unmarshal object into Go value of type string from here.

It seems that Reason should be a struct with two string fields type and reason, but I'm not sure if the response format depends on the version of Elasticsearch (currently I'm using 2.2.2).