亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將繼承的結構作為基礎對象傳回

將繼承的結構作為基礎對象傳回

Go
料青山看我應如是 2021-12-20 10:23:35
我確定這是一個語法問題,我還沒有用 Go 解決 -我得到的錯誤——不能在extractBucket的參數中使用*term(類型elastic.AggregationBucketKeyItem)作為類型elastic.Aggregations產生錯誤的那一行是"Value": extractBucket(parts[1:], *term),相關代碼,用于上下文// from https://github.com/olivere/elastic/blob/v3.0.22/search_aggs.gotype Aggregations map[string]*json.RawMessagetype AggregationBucketSignificantTerms struct {    Aggregations    DocCount int64                               //`json:"doc_count"`    Buckets  []*AggregationBucketSignificantTerm //`json:"buckets"`    Meta     map[string]interface{}              // `json:"meta,omitempty"`}// my codefunc 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 回答

?
拉風的咖菲貓

TA貢獻1995條經驗 獲得超2個贊

嵌入類型會使您“繼承”該類型,這是一個常見的誤解。即使AggregationBucketSignificantTerms 嵌入Aggregations,它也不是編譯器的一個。它只有一個 type 字段Aggregations,并在其頂層提供該類型的方法。感覺有點像繼承,但可能不是您對 Java 子類之類的東西所習慣的。

要解決它,您可以嘗試"Value": extractBucket(parts[1:], *term.Aggregations),,但我不清楚這是否會解決您的問題。


查看完整回答
反對 回復 2021-12-20
?
慕俠2389804

TA貢獻1719條經驗 獲得超6個贊

好吧,錯誤是不言自明的:

不能使用 (*term, variable name) (type elastic.AggregationBucketKeyItem <-- Variables current type) as (type elastic.Aggregations <-- Expected type) in argument to extractBucket

不管你的*term價值

產生者: for _, term := range terms.Buckets {

不是函數的正確類型

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

采取一種 elastic.Aggregations


查看完整回答
反對 回復 2021-12-20
  • 2 回答
  • 0 關注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號