传回继承的结构作为基础对象

I'm sure this is a syntax issue that I've yet to figure out with Go -

The error I'm getting --

cannot use *term (type elastic.AggregationBucketKeyItem) as type elastic.Aggregations in argument to extractBucket

The line that's generating the error is

"Value": extractBucket(parts[1:], *term),

The relevant code, for context

// from https://github.com/olivere/elastic/blob/v3.0.22/search_aggs.go

type Aggregations map[string]*json.RawMessage

type AggregationBucketSignificantTerms struct {
    Aggregations

    DocCount int64                               //`json:"doc_count"`
    Buckets  []*AggregationBucketSignificantTerm //`json:"buckets"`
    Meta     map[string]interface{}              // `json:"meta,omitempty"`
}

// my code

func extractBucket(parts []string, aggs elastic.Aggregations) interface{} {
    // bunch of code removed

           terms, found := aggs.Terms(part)
           for _, term := range terms.Buckets {
            if len(parts) == 0 {
                retval[(term.Key).(string)] = map[string]interface{}{
                    "Count": term.DocCount,
                }
            } else {
                retval[(term.Key).(string)] = map[string]interface{}{
                    "Count": term.DocCount,
                    "Value": extractBucket(parts[1:], *term),
                }
            }
        }
}

It is a common misunderstanding that embedding a type makes you "inherit" that type. Even though AggregationBucketSignificantTerms embeds an Aggregations, it is not one to the compiler. It merely has a field of type Aggregations, and it provides methods from that type at it's top level. It feels a bit like inheritance, but is probably not what you are used to with things like Java subclasses.

To solve it you can try "Value": extractBucket(parts[1:], *term.Aggregations),, but I am not clear if that will solve your problem or not.

Well the error is pretty self explanatory:

cannot use (*term, variable name) (type elastic.AggregationBucketKeyItem <-- Variables current type) as (type elastic.Aggregations <-- Expected type) in argument to extractBucket

Whatever your *term value

Generated by: for _, term := range terms.Buckets {

is not the right type for the function

extractBucket(parts []string, aggs elastic.Aggregations)

Takes a type of elastic.Aggregations