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

aggregations json unmarshal error #8

Open
almondyoung opened this issue Jul 28, 2023 · 4 comments
Open

aggregations json unmarshal error #8

almondyoung opened this issue Jul 28, 2023 · 4 comments

Comments

@almondyoung
Copy link

almondyoung commented Jul 28, 2023

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
Copy link
Author

almondyoung commented Jul 28, 2023

request like :

{
  "size": 0,
  "aggs": {
    "categories": {
      "terms": {
        "field": "category"
      }
    }
  }
}

@almondyoung
Copy link
Author

almondyoung commented Jul 28, 2023

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
Copy link
Collaborator

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

@lovehunter9
Copy link

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

Can go-elasticsearch request zinc directly without huge modification?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants