From f7cd93cc39a076ac88611a53456c10971ca9f9e1 Mon Sep 17 00:00:00 2001 From: Tim Holdaway Date: Thu, 16 Jan 2025 09:47:58 -0800 Subject: [PATCH 1/5] Add Highlight field to SearchHit struct Signed-off-by: Tim Holdaway --- opensearchapi/api_search.go | 1 + opensearchapi/api_search_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/opensearchapi/api_search.go b/opensearchapi/api_search.go index d207b985..acd4d55c 100644 --- a/opensearchapi/api_search.go +++ b/opensearchapi/api_search.go @@ -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 diff --git a/opensearchapi/api_search_test.go b/opensearchapi/api_search_test.go index 4339971b..0a59f60a 100644 --- a/opensearchapi/api_search_test.go +++ b/opensearchapi/api_search_test.go @@ -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{"bar"}}, resp.Hits.Hits[0].Highlight) + }) } From d7433107f5da8375bc5abcc91a342aeffb4daf6b Mon Sep 17 00:00:00 2001 From: Tim Holdaway Date: Thu, 16 Jan 2025 11:07:33 -0800 Subject: [PATCH 2/5] Update changelog Signed-off-by: Tim Holdaway --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 987603ec..6102d8b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 2ce8d15a144637d0bee59f65c12ec51502d2155f Mon Sep 17 00:00:00 2001 From: Tim Holdaway Date: Fri, 17 Jan 2025 13:24:31 -0800 Subject: [PATCH 3/5] Update SearchTemplate struct with Status field This field is returned since OpenSearch 2.18 Signed-off-by: Tim Holdaway --- opensearchapi/api_search-template.go | 1 + 1 file changed, 1 insertion(+) diff --git a/opensearchapi/api_search-template.go b/opensearchapi/api_search-template.go index f3c7715e..b79d9db2 100644 --- a/opensearchapi/api_search-template.go +++ b/opensearchapi/api_search-template.go @@ -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"` From 0d59886275ad5005e45d3a40ee86fbc8b43af7e5 Mon Sep 17 00:00:00 2001 From: Tim Holdaway Date: Fri, 17 Jan 2025 13:56:37 -0800 Subject: [PATCH 4/5] Update NodeStatsstruct with RemoteStore field This field is returned since OpenSearch 2.18. (see https://github.com/opensearch-project/OpenSearch/pull/15611) Signed-off-by: Tim Holdaway --- opensearchapi/api_nodes-stats.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/opensearchapi/api_nodes-stats.go b/opensearchapi/api_nodes-stats.go index b37c87d0..b9956086 100644 --- a/opensearchapi/api_nodes-stats.go +++ b/opensearchapi/api_nodes-stats.go @@ -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 @@ -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"` +} From 035de676171f807ea280dd7883e7b5a339b025bd Mon Sep 17 00:00:00 2001 From: Tim Holdaway Date: Fri, 17 Jan 2025 14:15:45 -0800 Subject: [PATCH 5/5] 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 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5e1c193d..a2d823c9 100644 --- a/Makefile +++ b/Makefile @@ -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;