Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add missing SeqNo and PrimaryTerm fields in SearchHit #574

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 @@ -9,6 +9,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Adds the `SearchPipelines` field to `SearchParams` ([#532](https://github.com/opensearch-project/opensearch-go/pull/532))
- Adds support for OpenSearch 2.14 ([#552](https://github.com/opensearch-project/opensearch-go/pull/552))
- Adds the `Caches` field to Node stats ([#572](https://github.com/opensearch-project/opensearch-go/pull/572))
- Adds the `SeqNo` and `PrimaryTerm` fields in `SearchHit` ([#574](https://github.com/opensearch-project/opensearch-go/pull/574))

### Changed
- Security roles get response struct has its own sub structs without omitempty ([#572](https://github.com/opensearch-project/opensearch-go/pull/572))
Expand Down
2 changes: 2 additions & 0 deletions opensearchapi/api_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@ type SearchHit struct {
Type string `json:"_type"` // Deprecated field
Sort []any `json:"sort"`
Explanation *DocumentExplainDetails `json:"_explanation"`
SeqNo *int `json:"_seq_no"`
PrimaryTerm *int `json:"_primary_term"`
}
38 changes: 38 additions & 0 deletions opensearchapi/api_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,42 @@ func TestSearch(t *testing.T) {
assert.NotEmpty(t, resp.Hits.Hits[0].Routing)
assert.Equal(t, "foo", resp.Hits.Hits[0].Routing)
})

t.Run("with seq_no and primary_term", func(t *testing.T) {
seqNoPrimaryTerm := true
resp, err := client.Search(nil, &opensearchapi.SearchReq{
Indices: []string{index},
Body: strings.NewReader(""),
Params: opensearchapi.SearchParams{
SeqNoPrimaryTerm: &seqNoPrimaryTerm,
},
})
require.Nil(t, err)
assert.NotNil(t, resp)
ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response)
assert.NotEmpty(t, resp.Hits.Hits)
for _, hit := range resp.Hits.Hits {
assert.NotNil(t, hit.SeqNo)
assert.NotNil(t, hit.PrimaryTerm)
}
})

t.Run("without seq_no and primary_term", func(t *testing.T) {
seqNoPrimaryTerm := false
resp, err := client.Search(nil, &opensearchapi.SearchReq{
Indices: []string{index},
Body: strings.NewReader(""),
Params: opensearchapi.SearchParams{
SeqNoPrimaryTerm: &seqNoPrimaryTerm,
},
})
require.Nil(t, err)
assert.NotNil(t, resp)
ostest.CompareRawJSONwithParsedJSON(t, resp, resp.Inspect().Response)
assert.NotEmpty(t, resp.Hits.Hits)
for _, hit := range resp.Hits.Hits {
assert.Nil(t, hit.SeqNo)
assert.Nil(t, hit.PrimaryTerm)
}
})
}
Loading