Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Highlight field to SearchHit struct #654

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
## [Unreleased]

### Added
- Adds `Highlight` field to `SearchHit` ([#654](https://github.com/opensearch-project/opensearch-go/pull/654))

### Changed

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ godoc: ## Display documentation for the package
godoc --http=localhost:6060 --play

cluster.build:
docker compose --project-directory .ci/opensearch build;
docker compose --project-directory .ci/opensearch build --pull;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗒️ This ensures that when running integration tests locally, docker isn't using an older cached version of opensearch:latest, and actually gets the most recent one that the CI build will be using.


cluster.start:
docker compose --project-directory .ci/opensearch up -d;
Expand Down
6 changes: 6 additions & 0 deletions opensearchapi/api_nodes-stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ type NodesStats struct {
Repositories []json.RawMessage `json:"repositories"`
AdmissionControl NodesStatsAdmissionControl `json:"admission_control"`
Caches NodesStatsCaches `json:"caches"`
RemoteStore NodeStatsRemoteStore `json:"remote_store"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗒️ Integration tests were failing due to this field that was added to the opensearch 2.18 response. The test was comparing the parsed response to the raw response and failing on the missing field.
See opensearch-project/OpenSearch#15611 for where this was added to 2.18

}

// NodesStatsIndices is a sub type of NodesStats representing Indices information of the node
Expand Down Expand Up @@ -729,3 +730,8 @@ type NodesStatsCaches struct {
StoreName string `json:"store_name"`
} `json:"request_cache"`
}

// NodeStatsRemoteStore is a sub type of NodesStats
type NodeStatsRemoteStore struct {
LastSuccessfulFetchOfPinnedTimestamps int `json:"last_successful_fetch_of_pinned_timestamps"`
}
1 change: 1 addition & 0 deletions opensearchapi/api_search-template.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type SearchTemplateResp struct {
Took int `json:"took"`
Timeout bool `json:"timed_out"`
Shards ResponseShards `json:"_shards"`
Status int `json:"status"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗒️ Integration tests were failing due to this field that was added to the opensearch 2.18 response. The test was comparing the parsed response to the raw response and failing on the missing field.

Hits struct {
Total struct {
Value int `json:"value"`
Expand Down
1 change: 1 addition & 0 deletions opensearchapi/api_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type SearchHit struct {
Explanation *DocumentExplainDetails `json:"_explanation"`
SeqNo *int `json:"_seq_no"`
PrimaryTerm *int `json:"_primary_term"`
Highlight map[string][]string `json:"highlight"`
}

// Suggest is a sub type of SearchResp containing information of the suggest field
Expand Down
24 changes: 24 additions & 0 deletions opensearchapi/api_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,28 @@ func TestSearch(t *testing.T) {
require.Nil(t, err)
assert.NotEmpty(t, resp.Suggest)
})

t.Run("request with highlight", func(t *testing.T) {
resp, err := client.Search(
nil,
&opensearchapi.SearchReq{
Indices: []string{index},
Body: strings.NewReader(`{
"query": {
"match": {
"foo": "bar"
}
},
"highlight": {
"fields": {
"foo": {}
}
}
}`),
},
)
require.Nil(t, err)
assert.NotEmpty(t, resp.Hits.Hits)
assert.Equal(t, map[string][]string{"foo": []string{"<em>bar</em>"}}, resp.Hits.Hits[0].Highlight)
})
}
Loading