Skip to content

Commit

Permalink
Expose ShardInfo and add ShardFailure
Browse files Browse the repository at this point in the history
This commit renames `shardInfo` to `ShardInfo`, exposing its interface
to the outside. It also aligns its usage in structs to always use
`*ShardInfo`. Finally, `ShardInfo` is completed; it was missing the
`failures` field, which is now exposed as a `ShardFailure`.

Close #969
  • Loading branch information
olivere committed Nov 30, 2018
1 parent c6466b2 commit 423cdb4
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion bulk.go
Expand Up @@ -325,7 +325,7 @@ type BulkResponseItem struct {
Id string `json:"_id,omitempty"`
Version int64 `json:"_version,omitempty"`
Result string `json:"result,omitempty"`
Shards *shardsInfo `json:"_shards,omitempty"`
Shards *ShardsInfo `json:"_shards,omitempty"`
SeqNo int64 `json:"_seq_no,omitempty"`
PrimaryTerm int64 `json:"_primary_term,omitempty"`
Status int `json:"status,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions count.go
Expand Up @@ -321,6 +321,6 @@ func (s *CountService) Do(ctx context.Context) (int64, error) {

// CountResponse is the response of using the Count API.
type CountResponse struct {
Count int64 `json:"count"`
Shards shardsInfo `json:"_shards,omitempty"`
Count int64 `json:"count"`
Shards *ShardsInfo `json:"_shards,omitempty"`
}
2 changes: 1 addition & 1 deletion delete.go
Expand Up @@ -221,7 +221,7 @@ type DeleteResponse struct {
Id string `json:"_id,omitempty"`
Version int64 `json:"_version,omitempty"`
Result string `json:"result,omitempty"`
Shards *shardsInfo `json:"_shards,omitempty"`
Shards *ShardsInfo `json:"_shards,omitempty"`
SeqNo int64 `json:"_seq_no,omitempty"`
PrimaryTerm int64 `json:"_primary_term,omitempty"`
Status int `json:"status,omitempty"`
Expand Down
25 changes: 14 additions & 11 deletions errors.go
Expand Up @@ -164,17 +164,20 @@ func IsStatusCode(err interface{}, code int) bool {

// -- General errors --

// shardsInfo represents information from a shard.
type shardsInfo struct {
Total int `json:"total"`
Successful int `json:"successful"`
Failed int `json:"failed"`
// ShardsInfo represents information from a shard.
type ShardsInfo struct {
Total int `json:"total"`
Successful int `json:"successful"`
Failed int `json:"failed"`
Failures []*ShardFailure `json:"failures,omitempty"`
}

// shardOperationFailure represents a shard failure.
type shardOperationFailure struct {
Shard int `json:"shard"`
Index string `json:"index"`
Status string `json:"status"`
// "reason"
// ShardFailure represents details about a failure.
type ShardFailure struct {
Index string `json:"_index,omitempty"`
Shard int `json:"_shard,omitempty"`
Node string `json:"_node,omitempty"`
Reason map[string]interface{} `json:"reason,omitempty"`
Status string `json:"status,omitempty"`
Primary bool `json:"primary,omitempty"`
}
2 changes: 1 addition & 1 deletion index.go
Expand Up @@ -292,7 +292,7 @@ type IndexResponse struct {
Id string `json:"_id,omitempty"`
Version int64 `json:"_version,omitempty"`
Result string `json:"result,omitempty"`
Shards *shardsInfo `json:"_shards,omitempty"`
Shards *ShardsInfo `json:"_shards,omitempty"`
SeqNo int64 `json:"_seq_no,omitempty"`
PrimaryTerm int64 `json:"_primary_term,omitempty"`
Status int `json:"status,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion indices_flush.go
Expand Up @@ -169,5 +169,5 @@ func (s *IndicesFlushService) Do(ctx context.Context) (*IndicesFlushResponse, er
// -- Result of a flush request.

type IndicesFlushResponse struct {
Shards shardsInfo `json:"_shards"`
Shards *ShardsInfo `json:"_shards"`
}
2 changes: 1 addition & 1 deletion indices_flush_synced.go
Expand Up @@ -143,7 +143,7 @@ func (s *IndicesSyncedFlushService) Do(ctx context.Context) (*IndicesSyncedFlush

// IndicesSyncedFlushResponse is the outcome of a synched flush call.
type IndicesSyncedFlushResponse struct {
Shards shardsInfo `json:"_shards"`
Shards *ShardsInfo `json:"_shards"`
Index map[string]*IndicesShardsSyncedFlushResult `json:"-"`

// TODO Add information about the indices here from the root level
Expand Down
2 changes: 1 addition & 1 deletion indices_forcemerge.go
Expand Up @@ -180,5 +180,5 @@ func (s *IndicesForcemergeService) Do(ctx context.Context) (*IndicesForcemergeRe

// IndicesForcemergeResponse is the response of IndicesForcemergeService.Do.
type IndicesForcemergeResponse struct {
Shards shardsInfo `json:"_shards"`
Shards *ShardsInfo `json:"_shards"`
}
2 changes: 1 addition & 1 deletion indices_refresh.go
Expand Up @@ -94,5 +94,5 @@ func (s *RefreshService) Do(ctx context.Context) (*RefreshResult, error) {

// RefreshResult is the outcome of RefreshService.Do.
type RefreshResult struct {
Shards shardsInfo `json:"_shards,omitempty"`
Shards *ShardsInfo `json:"_shards,omitempty"`
}
2 changes: 1 addition & 1 deletion indices_segments.go
Expand Up @@ -174,7 +174,7 @@ func (s *IndicesSegmentsService) Do(ctx context.Context) (*IndicesSegmentsRespon
// IndicesSegmentsResponse is the response of IndicesSegmentsService.Do.
type IndicesSegmentsResponse struct {
// Shards provides information returned from shards.
Shards shardsInfo `json:"_shards"`
Shards *ShardsInfo `json:"_shards"`

// Indices provides a map into the stats of an index.
// The key of the map is the index name.
Expand Down
2 changes: 1 addition & 1 deletion indices_stats.go
Expand Up @@ -200,7 +200,7 @@ func (s *IndicesStatsService) Do(ctx context.Context) (*IndicesStatsResponse, er
// IndicesStatsResponse is the response of IndicesStatsService.Do.
type IndicesStatsResponse struct {
// Shards provides information returned from shards.
Shards shardsInfo `json:"_shards"`
Shards *ShardsInfo `json:"_shards"`

// All provides summary stats about all indices.
All *IndexStats `json:"_all,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion search.go
Expand Up @@ -435,7 +435,7 @@ type SearchResult struct {
TimedOut bool `json:"timed_out,omitempty"` // true if the search timed out
Error *ErrorDetails `json:"error,omitempty"` // only used in MultiGet
Profile *SearchProfile `json:"profile,omitempty"` // profiling results, if optional Profile API was active for this search
Shards *shardsInfo `json:"_shards,omitempty"` // shard information
Shards *ShardsInfo `json:"_shards,omitempty"` // shard information
}

// TotalHits is a convenience function to return the number of hits for
Expand Down
8 changes: 4 additions & 4 deletions search_shards.go
Expand Up @@ -169,12 +169,12 @@ func (s *SearchShardsService) Do(ctx context.Context) (*SearchShardsResponse, er

// SearchShardsResponse is the response of SearchShardsService.Do.
type SearchShardsResponse struct {
Nodes map[string]interface{} `json:"nodes"`
Indices map[string]interface{} `json:"indices"`
Shards [][]ShardsInfo `json:"shards"`
Nodes map[string]interface{} `json:"nodes"`
Indices map[string]interface{} `json:"indices"`
Shards [][]*SearchShardsResponseShardsInfo `json:"shards"`
}

type ShardsInfo struct {
type SearchShardsResponseShardsInfo struct {
Index string `json:"index"`
Node string `json:"node"`
Primary bool `json:"primary"`
Expand Down
2 changes: 1 addition & 1 deletion snapshot_create.go
Expand Up @@ -186,6 +186,6 @@ type SnapshotCreateResponse struct {
EndTimeInMillis int64 `json:"end_time_in_millis"`
DurationInMillis int64 `json:"duration_in_millis"`
Failures []SnapshotShardFailure `json:"failures"`
Shards shardsInfo `json:"shards"`
Shards *ShardsInfo `json:"shards"`
} `json:"snapshot"`
}
2 changes: 1 addition & 1 deletion update.go
Expand Up @@ -321,7 +321,7 @@ type UpdateResponse struct {
Id string `json:"_id,omitempty"`
Version int64 `json:"_version,omitempty"`
Result string `json:"result,omitempty"`
Shards *shardsInfo `json:"_shards,omitempty"`
Shards *ShardsInfo `json:"_shards,omitempty"`
SeqNo int64 `json:"_seq_no,omitempty"`
PrimaryTerm int64 `json:"_primary_term,omitempty"`
Status int `json:"status,omitempty"`
Expand Down

0 comments on commit 423cdb4

Please sign in to comment.