Issues with Zincsearch's Go-SDK and JSON Deserialization

TLDR alanx encountered a deserialization issue with Zincsearch's go-sdk. Prabhat recommended using go-elasticsearch, which resolved the problem.

Photo of alanx
alanx
Thu, 09 Mar 2023 06:18:15 UTC

Hello, I'm trying to use zincsearch's go-sdk to do aggregation queries, but it looks like the sdk doesn't do proper JSON deserialization based on the real type of MetaAggregationResponse.Bucket.

Photo of alanx
alanx
Thu, 09 Mar 2023 06:19:21 UTC

The error msg is: Error when calling `SearchApi.Search``: json: cannot unmarshal array into Go struct field MetaAggregationResponse.aggregations.buckets of type map[string]interface {}. Not sure if I'm using it incorrectly, hope someone can answer this question

Photo of alanx
alanx
Thu, 09 Mar 2023 06:25:34 UTC

Debug the code locally and find that the error appears on line 430 of api_search.go. Before this line of code, the JSON data body returned by the server has been correctly obtained.

Photo of Prabhat
Prabhat
Fri, 10 Mar 2023 01:01:47 UTC

SDK might be a little old and we may need to update it. Can you try

Photo of alanx
alanx
Fri, 10 Mar 2023 02:27:45 UTC

I've tried it and it works, thanks.

Photo of Prabhat
Prabhat
Fri, 10 Mar 2023 02:27:55 UTC

cool