doushi1900 2016-02-29 00:00
浏览 31
已采纳

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

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),
                }
            }
        }
}
  • 写回答

2条回答 默认 最新

  • du8589840 2016-02-29 00:53
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?