Handle non-string errors for ES 2+ support

This commit is contained in:
Paul Bonser 2016-10-13 19:37:40 -05:00
parent 2715203d96
commit 5d13647d3c
2 changed files with 12 additions and 1 deletions

View File

@ -516,6 +516,13 @@ func (c *Client) Do(r Requester) (*Response, error) {
}
}
if len(esResp.RawError) > 0 && esResp.RawError[0] == '"' {
json.Unmarshal(esResp.RawError, &esResp.Error)
} else {
esResp.Error = string(esResp.RawError)
}
esResp.RawError = nil
if esResp.Error != "" {
return esResp, &SearchError{esResp.Error, esResp.Status}
}

View File

@ -4,7 +4,10 @@
package goes
import "net/http"
import (
"encoding/json"
"net/http"
)
// Client represents a connection to elasticsearch
type Client struct {
@ -23,6 +26,7 @@ type Client struct {
type Response struct {
Acknowledged bool
Error string
RawError json.RawMessage `json:"error"`
Errors bool
Status uint64
Took uint64