zincsearch / sdk-go-zincsearch

Go SDK Client for ZincSearch
https://docs.zincsearch.com
Apache License 2.0
33 stars 5 forks source link

aggregations json unmarshal error #8

Open almondyoung opened 1 year ago

almondyoung commented 1 year ago

cannot unmarshal array into Go struct field MetaAggregationResponse.aggregations.buckets of type map[string]interface {}

// MetaAggregationResponse struct for MetaAggregationResponse
type MetaAggregationResponse struct {
    // slice or map
    Buckets map[string]interface{} `json:"buckets,omitempty"`
    // support for auto_date_histogram_aggregation
    Interval *string `json:"interval,omitempty"`
    Value map[string]interface{} `json:"value,omitempty"`
}

buckets not support slice

func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) {
//---
                } else if err = json.Unmarshal(b, v); err != nil { // simple model
            return err
        }
//---
almondyoung commented 1 year ago

request like :

{
  "size": 0,
  "aggs": {
    "categories": {
      "terms": {
        "field": "category"
      }
    }
  }
}
almondyoung commented 1 year ago

response like:

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 14
        },
        "max_score": 1,
        "hits": []
    },
    "aggregations": {
        "categories": {
            "buckets": [
                {
                    "doc_count": 8,
                    "key": "xx"
                },
                {
                    "doc_count": 2,
                    "key": "xxx"
                },
                {
                    "doc_count": 2,
                    "key": "xxxx"
                },
                {
                    "doc_count": 1,
                    "key": "xxxxx"
                },
                {
                    "doc_count": 1,
                    "key": "xxxxxx"
                }
            ]
        }
    }
}
hengfeiyang commented 1 year ago

Suggest use https://github.com/elastic/go-elasticsearch v7, this SDK is not good.

lovehunter9 commented 1 year ago

Suggest use https://github.com/elastic/go-elasticsearch v7, this SDK is not good.

Can go-elasticsearch request zinc directly without huge modification?