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

[BUG] Highlight results are not returned on search results. #653

Closed
tim-holdaway-clever opened this issue Jan 16, 2025 · 1 comment · Fixed by #654
Closed

[BUG] Highlight results are not returned on search results. #653

tim-holdaway-clever opened this issue Jan 16, 2025 · 1 comment · Fixed by #654
Labels
bug Something isn't working untriaged

Comments

@tim-holdaway-clever
Copy link
Contributor

tim-holdaway-clever commented Jan 16, 2025

What is the bug?

When calling opensearchapi.Client.Search with a query with a highlight specified, the highlight results coming back in the raw json coming back from the OpenSearch cluster are not returned on the SearchHits in the SearchResp.

How can one reproduce the bug?

Call opensearchapi.Client.Search() with a SearchReq with a body with a highlight property specifying highlights for fields that match in they query.

What is the expected behavior?

The SearchResp coming back from Client.Search should include the highlight results in the SearchHits, as they are returned in the raw json api response from the OpenSearch cluster.

What is your host/environment?

using opensearch-go@v4.3.0 on mac os 14.7.2 and running in aws lambda.
querying Amazon OpenSearch Service 2.15 cluster.

Do you have any screenshots?

Do you have any additional context?

It seems like the highlight field is already coming back in the raw json, and just needs to be added to SearchHit so that it will be populated when the json response is unmarshalled, like this:

 type SearchHit struct {
        Index       string                  `json:"_index"`
        ID          string                  `json:"_id"`
        Routing     string                  `json:"_routing"`
        Score       float32                 `json:"_score"`
        Source      json.RawMessage         `json:"_source"`
        Fields      json.RawMessage         `json:"fields"`
        Type        string                  `json:"_type"` // Deprecated field
        Sort        []any                   `json:"sort"`
        Explanation *DocumentExplainDetails `json:"_explanation"`
        SeqNo       *int                    `json:"_seq_no"`
        PrimaryTerm *int                    `json:"_primary_term"`
+       Highlight  map[string][]string     `json:"highlight"`
 }

I'm happy to investigate this further and PR it, if it's not already in the works to add this field to the response.

@tim-holdaway-clever
Copy link
Contributor Author

Hi @dblock, what do you think about adding support for returning the highlight results on SearchHit like this? The linked draft PR should accomplish this, with integration test for it. I'm not sure what the failing tests are about -- seem unrelated and like they're failing in other recent PRs -- so I left the PR as draft until someone with more context can assess those.

It would be awesome if this missing field is something we could add to opensearch-go, so let me know what you think and if there's anything else I need to do on that PR to help move it along!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working untriaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant