Skip to content

Commit

Permalink
add fields to document get api response
Browse files Browse the repository at this point in the history
Signed-off-by: Bundit Jitkonghcuen <boybundit@hotmail.com>
  • Loading branch information
boybundit committed Apr 15, 2024
1 parent c685fa6 commit 3c78731
Show file tree
Hide file tree
Showing 3 changed files with 43 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
41 changes: 41 additions & 0 deletions opensearchapi/api_document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,5 +393,46 @@ 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.Create(nil,
opensearchapi.IndicesCreateReq{
Index: index,
Body: strings.NewReader(`{
"mappings": {
"properties": {
"foo-stored": {
"type": "keyword",
"store":true
}
}
}
}`),
})
require.Nil(t, err)
_, err = client.Document.Create(
nil,
opensearchapi.DocumentCreateReq{
Index: index,
Body: strings.NewReader(`{"foo-stored": "bar"}`),
DocumentID: documentID,
},
)
require.Nil(t, err)
res, err := client.Document.Get(
nil,
opensearchapi.DocumentGetReq{
Index: index,
DocumentID: documentID,
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 3c78731

Please # to comment.