我確定這是一個語法問題,我還沒有用 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),
,但我不清楚這是否會解決您的問題。

慕俠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
- 2 回答
- 0 關注
- 150 瀏覽
添加回答
舉報
0/150
提交
取消