Working on a project that uses OpenSearch for search, and I’m running into a strange issue where the request I make on Insomnia (an Desktop API client app) will return different scores than the request I make in my Go code via Resty.
This is the request I’m making in Insomnia:
GET /clubs/_search
{"query":{"query_string":{"query":"Linguistics"}}}
Content-Type is set to application/json
as well.
This is the request I’m making in my Go code:
queryJson, err := query.ToJson() // I've checked, and queryJson is the exact same text as the Insomnia request.
<... err handling code omitted ...>
client := resty.New()
resp, err := client.R().
SetHeader("Content-Type", "application/json").
SetBody(queryJson).
Get(fmt.Sprintf("%s/clubs/_search", constants.SEARCH_URL))
<... err handling code omitted ...>
var responseData search.SearchEndpointResponse // This will be unmarshaled into valid JSON, just not correct/expected data.
err = json.Unmarshal(resp.Body(), &responseData)
if err != nil {
return nil, err
}
ids := make([]string, len(responseData.Hits.Hits))
for i, result := range responseData.Hits.Hits {
ids[i] = result.Id
}
var clubs []models.Club
if err = db.Model(&models.Club{}).Preload("Tag").Where("id IN ?", ids).Find(&clubs).Error; err != nil {
return nil, nil
}
return &search.ClubSearchResult{
Results: clubs,
}, nil
What is strange is that the Insomnia request will return JSON with just 1 club, a Linguistics Club that I have in my development/seeding data. And it will return with a _score
of 3.263. Whereas, with the request in Go code, it will return JSON with all 10 clubs I have for development/seeding data, all with a score of 1.000.
I’ve tried replacing the argument in the .SetBody()
call with a string literal to no avail. What I also find interesting is that if I replace the argument in .SetBody()
with spam characters (i.e .SetBody("ajkdlflaskj")
), the behavior is still the same: returning all 10 clubs I have for seeding data.
What can I do to fix this? Thank you!