Skip to content

Commit

Permalink
Adds the Fields field containing the document fields to the `Search…
Browse files Browse the repository at this point in the history
…Hit` struct (#508)

Signed-off-by: Ponlawat Suparat <thekogo@gmail.com>
  • Loading branch information
thekogo authored Apr 4, 2024
1 parent 392013b commit f3ad333
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
## [Unreleased]

### Added
- Adds GlobalIOUsage struct for nodes stats ([#506]((https://github.com/opensearch-project/opensearch-go/pull/506))
- Adds GlobalIOUsage struct for nodes stats ([#506]((https://github.com/opensearch-project/opensearch-go/pull/506)))

- Adds the `Explanation` field containing the document explain details to the `SearchHit` struct. ([#504](https://github.com/opensearch-project/opensearch-go/pull/504)
- Adds the `Explanation` field containing the document explain details to the `SearchHit` struct. ([#504](https://github.com/opensearch-project/opensearch-go/pull/504))
- Adds the `Fields` field containing the document fields to the `SearchHit` struct. ([#508](https://github.com/opensearch-project/opensearch-go/pull/508))
### Changed
- Use docker compose v2 instead of v1 ([#506]((https://github.com/opensearch-project/opensearch-go/pull/506))

Expand Down
3 changes: 2 additions & 1 deletion opensearchapi/api_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type SearchResp struct {
response *opensearch.Response
}

// Inspect returns the Inspect type containing the raw *opensearch.Reponse
// Inspect returns the Inspect type containing the raw *opensearch.Response
func (r SearchResp) Inspect() Inspect {
return Inspect{Response: r.response}
}
Expand All @@ -91,6 +91,7 @@ type SearchHit struct {
ID string `json:"_id"`
Score float32 `json:"_score"`
Source json.RawMessage `json:"_source"`
Fields json.RawMessage `json:"fields"`
Type string `json:"_type"` // Deprecated field
Sort []any `json:"sort"`
Explanation *DocumentExplainDetails `json:"_explanation"`
Expand Down
17 changes: 17 additions & 0 deletions opensearchapi/api_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,21 @@ func TestSearch(t *testing.T) {
assert.NotEmpty(t, resp.Hits.Hits)
assert.NotNil(t, resp.Hits.Hits[0].Explanation)
})

t.Run("request with retrieve specific fields", func(t *testing.T) {
resp, err := client.Search(nil, &opensearchapi.SearchReq{Indices: []string{index}, Body: strings.NewReader(`{
"query": {
"match": {
"foo": "bar"
}
},
"fields": [
"foo"
],
"_source": false
}`)})
require.Nil(t, err)
assert.NotEmpty(t, resp.Hits.Hits)
assert.NotEmpty(t, resp.Hits.Hits[0].Fields)
})
}

0 comments on commit f3ad333

Please sign in to comment.