我确定这是一个语法问题,我还没有用 Go 解决 -
我得到的错误——
不能在extractBucket的参数中使用*term(类型elastic.AggregationBucketKeyItem)作为类型elastic.Aggregations
产生错误的那一行是
"Value": extractBucket(parts[1:], *term),
相关代码,用于上下文
// 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),
}
}
}
}
拉风的咖菲猫
慕侠2389804
相关分类