Skip to content

Commit

Permalink
Add the Total fields to the SearchResp struct
Browse files Browse the repository at this point in the history
Signed-off-by: rjsadow <richard.j.sadowski@gmail.com>
  • Loading branch information
rjsadow committed Oct 17, 2024
1 parent 3d87486 commit 375d0c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions opensearchapi/api_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ type SearchResp struct {
ScrollID *string `json:"_scroll_id,omitempty"`
Suggest map[string][]Suggest `json:"suggest,omitempty"`
response *opensearch.Response
Total struct {
Value int `json:"value"`
Relation string `json:"relation"`
} `json:"total"`
}

// Inspect returns the Inspect type containing the raw *opensearch.Response
Expand Down
13 changes: 13 additions & 0 deletions opensearchapi/api_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,17 @@ func TestSearch(t *testing.T) {
require.Nil(t, err)
assert.NotEmpty(t, resp.Suggest)
})

t.Run("request with track_total_hits", func(t *testing.T) {
resp, err := client.Search(nil, &opensearchapi.SearchReq{Indices: []string{index}, Body: strings.NewReader(`{
"track_total_hits": true,
"query": {
"match": {
"foo": "bar"
}
}
}`)})
require.Nil(t, err)
assert.NotZero(t, resp.Total.Value)
})
}

0 comments on commit 375d0c6

Please sign in to comment.