Skip to content

Commit

Permalink
Add Highlight field to SearchHit struct (#654)
Browse files Browse the repository at this point in the history
* Add Highlight field to SearchHit struct

Signed-off-by: Tim Holdaway <[email protected]>

* Update changelog

Signed-off-by: Tim Holdaway <[email protected]>

* Update SearchTemplate struct with Status field

This field is returned since OpenSearch 2.18

Signed-off-by: Tim Holdaway <[email protected]>

* Update NodeStatsstruct with RemoteStore field

This field is returned since OpenSearch 2.18.
(see opensearch-project/OpenSearch#15611)

Signed-off-by: Tim Holdaway <[email protected]>

* Always attempt to pull the docker base image for integration tests.

Otherwise we can end up with a cached version of opensearch:latest that is not the current latest, and would use that instead,
resulting in tests running against a different version than in the CI build.

Signed-off-by: Tim Holdaway <[email protected]>

---------

Signed-off-by: Tim Holdaway <[email protected]>
  • Loading branch information
tim-holdaway-clever authored Jan 18, 2025
1 parent f81866a commit 040f709
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
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;

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"`
}

// 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"`
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)
})
}

0 comments on commit 040f709

Please sign in to comment.