Skip to content

Commit

Permalink
add fields to document get api response (#526)
Browse files Browse the repository at this point in the history
Signed-off-by: Bundit Jitkonghcuen <boybundit@hotmail.com>
  • Loading branch information
boybundit authored Apr 15, 2024
1 parent c685fa6 commit 51f1e77
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Adds security plugin ([#507](https://github.com/opensearch-project/opensearch-go/pull/507))
- Adds security settings to container for security testing ([#507](https://github.com/opensearch-project/opensearch-go/pull/507))
- Adds cluster.get-certs to copy admin certs out of the container ([#507](https://github.com/opensearch-project/opensearch-go/pull/507))
- Add the `Fields` field containing stored fields to the `DocumentGetResp` struct (#526)[https://github.com/opensearch-project/opensearch-go/pull/526]

### Changed
- Uses docker compose v2 instead of v1 ([#506](https://github.com/opensearch-project/opensearch-go/pull/506))
Expand Down
1 change: 1 addition & 0 deletions opensearchapi/api_document-get.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type DocumentGetResp struct {
Found bool `json:"found"`
Type string `json:"_type"` // Deprecated field
Source json.RawMessage `json:"_source"`
Fields json.RawMessage `json:"fields"`
response *opensearch.Response
}

Expand Down
39 changes: 39 additions & 0 deletions opensearchapi/api_document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,5 +393,44 @@ func TestDocumentClient(t *testing.T) {
assert.NotNil(t, res.Inspect().Response)
ostest.CompareRawJSONwithParsedJSON(t, res.Source, res.Inspect().Response)
})
t.Run("Fields", func(t *testing.T) {
_, err := client.Indices.Mapping.Put(nil,
opensearchapi.MappingPutReq{
Indices: []string{index},
Body: strings.NewReader(`{
"properties": {
"foo-stored": {
"type": "text",
"store":true
}
}
}`),
})
require.Nil(t, err)
_, err = client.Document.Create(
nil,
opensearchapi.DocumentCreateReq{
Index: index,
Body: strings.NewReader(`{"foo-stored": "bar"}`),
DocumentID: "test-stored-field",
},
)
require.Nil(t, err)
res, err := client.Document.Get(
nil,
opensearchapi.DocumentGetReq{
Index: index,
DocumentID: "test-stored-field",
Params: opensearchapi.DocumentGetParams{
StoredFields: []string{"foo-stored"},
},
},
)
require.Nil(t, err)
require.NotNil(t, res)
assert.NotNil(t, res.Inspect().Response)
ostest.CompareRawJSONwithParsedJSON(t, res, res.Inspect().Response)
assert.NotEmpty(t, res.Fields)
})
})
}

0 comments on commit 51f1e77

Please sign in to comment.