typesense / typesense/typesense-go
Unable to make search query with group by, with the error: json: cannot unmarshal number into Go struct field SearchGroupedHit.grouped_hits.group_key of type map[string]interface {}
Open
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 319
- Forks
- 73
- PR merge metrics
- No merged PRs in 30d
Description
Description
When I make a search query with group by, I get the error
json: cannot unmarshal number into Go struct field SearchGroupedHit.grouped_hits.group_key of type map[string]interface {}
Steps to reproduce
filterString := fmt.Sprintf("productSlug:=%s", productSlug)
searchParams := &api.SearchCollectionParams{
Q: "*",
QueryBy: "searchText0,searchText1,searchText2",
FilterBy: &filterString,
GroupBy: utils.Ref("productID"), // utils.Ref just gets a pointer
GroupLimit: utils.Ref(1),
}
resp, err := tsClient.Collection(collection).Documents().Search(searchParams)
And here's the schema
{
"name": "product_variants_all",
"fields": [
{
"name": "searchText0",
"type": "string",
"facet": false,
"optional": false,
"index": true,
"sort": false,
"infix": false,
"locale": ""
},
{
"name": "productSlug",
"type": "string",
"facet": false,
"optional": false,
"index": true,
"sort": false,
"infix": false,
"locale": ""
},
{
"name": "searchText1",
"type": "string",
"facet": false,
"optional": false,
"index": true,
"sort": false,
"infix": false,
"locale": ""
},
{
"name": "searchText2",
"type": "string",
"facet": false,
"optional": false,
"index": true,
"sort": false,
"infix": false,
"locale": ""
},
{
"name": "rankingScore",
"type": "float",
"facet": false,
"optional": false,
"index": true,
"sort": true,
"infix": false,
"locale": ""
},
{
"name": "productID",
"type": "int32",
"facet": true,
"optional": false,
"index": true,
"sort": true,
"infix": false,
"locale": ""
}
],
"default_sorting_field": "rankingScore",
"enable_nested_fields": true,
"symbols_to_index": [],
"token_separators": []
}
Expected Behavior
No error
Actual Behavior
Unmarshal error
Metadata
Typesense Version: 0.24.1
OS: Ubuntu 22.04
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the SearchCollectionParams and Documents().Search entry points, then inspect how SearchGroupedHit.grouped_hits.group_key is decoded. Reproduce the grouped search using the schema and Go example, and verify that a numeric productID group key completes without an unmarshal error and is returned correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- search
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100