Handling errors in bulk indexing. There is a filed named erros which indicates whether commit was succesful see: http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/bulk.html

This commit is contained in:
r--w 2014-10-13 09:11:12 +02:00
parent 7a0373c858
commit c4d6ac023a
2 changed files with 14 additions and 0 deletions

11
goes.go
View File

@ -350,6 +350,17 @@ func (req *Request) Run() (Response, error) {
return Response{}, err return Response{}, err
} }
if req.api == "_bulk" && esResp.Errors {
for _, item := range esResp.Items {
for _, i := range item {
if i.Error != "" {
return Response{}, &SearchError{i.Error, i.Status}
}
}
}
return Response{}, &SearchError{Msg: "Unknown error while bulk indexing"}
}
if esResp.Error != "" { if esResp.Error != "" {
return Response{}, &SearchError{esResp.Error, esResp.Status} return Response{}, &SearchError{esResp.Error, esResp.Status}
} }

View File

@ -59,6 +59,7 @@ type Request struct {
type Response struct { type Response struct {
Acknowledged bool Acknowledged bool
Error string Error string
Errors bool
Status uint64 Status uint64
Took uint64 Took uint64
TimedOut bool `json:"timed_out"` TimedOut bool `json:"timed_out"`
@ -111,6 +112,8 @@ type Item struct {
Id string `json:"_id"` Id string `json:"_id"`
Index string `json:"_index"` Index string `json:"_index"`
Version int `json:"_version"` Version int `json:"_version"`
Error string `json:"error"`
Status uint64 `json:"status"`
} }
// Represents the "_all" field when calling the _stats API // Represents the "_all" field when calling the _stats API