Skip to content

Commit

Permalink
Add shards information to search response
Browse files Browse the repository at this point in the history
Search results return information about the shards in `_shards`.
This is now part of the `SearchResult`.

Close #373
  • Loading branch information
olivere committed Oct 16, 2016
1 parent 2196066 commit 1ad75b5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ John Goodall [@jgoodall](https://github.com/jgoodall)
John Stanford [@jxstanford](https://github.com/jxstanford)
Junpei Tsuji [@jun06t](https://github.com/jun06t)
Kenta SUZUKI [@suzuken](https://github.com/suzuken)
Kyle Brandt [@kylebrandt](https://github.com/kylebrandt)
Maciej Lisiewski [@c2h5oh](https://github.com/c2h5oh)
Mara Kim [@autochthe](https://github.com/autochthe)
Marcy Buccellato [@marcybuccellato](https://github.com/marcybuccellato)
Expand Down
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

const (
// Version is the current version of Elastic.
Version = "3.0.55"
Version = "3.0.56"

// DefaultUrl is the default endpoint of Elasticsearch on the local machine.
// It is used e.g. when initializing a new Client without a specific URL.
Expand Down
3 changes: 2 additions & 1 deletion search.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ type SearchResult struct {
TerminatedEarly bool `json:"terminated_early"` // true if the operation has terminated before e.g. an expiration was reached
//Error string `json:"error,omitempty"` // used in MultiSearch only
// TODO double-check that MultiGet now returns details error information
Error *ErrorDetails `json:"error,omitempty"` // only used in MultiGet
Error *ErrorDetails `json:"error,omitempty"` // only used in MultiGet
Shards *shardsInfo `json:"_shards,omitempty"` // shard information
}

// TotalHits is a convenience function to return the number of hits for
Expand Down
22 changes: 22 additions & 0 deletions search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1020,3 +1020,25 @@ func TestSearchBuildURL(t *testing.T) {
}
}
}

func TestSearchResultHasShards(t *testing.T) {
//client := setupTestClientAndCreateIndexAndAddDocs(t, SetTraceLog(log.New(os.Stdout, "", log.LstdFlags)))
client := setupTestClientAndCreateIndexAndAddDocs(t)

// Match all should return all documents
searchResult, err := client.Search().
Index(testIndexName).
Query(NewMatchAllQuery()).
Size(100).
Pretty(true).
Do()
if err != nil {
t.Fatal(err)
}
if searchResult.Shards == nil {
t.Errorf("expected SearchResult.Shards != nil; got nil")
}
if got, want := searchResult.Shards.Failed, 0; got != want {
t.Errorf("expected SearchResult.Shards.Failed = %d; got %d", want, got)
}
}

0 comments on commit 1ad75b5

Please sign in to comment.