Explorar o código

feat:增加方法

wangchuanjin %!s(int64=2) %!d(string=hai) anos
pai
achega
dbbf1caeac
Modificáronse 3 ficheiros con 21 adicións e 3 borrados
  1. 19 1
      es/es.go
  2. 1 1
      es/esv1.go
  3. 1 1
      es/esv7.go

+ 19 - 1
es/es.go

@@ -32,7 +32,25 @@ const (
 	HL_IK           = `"highlight": {"pre_tags": ["` + IK_pre_tags + `"],"post_tags": ["` + IK_post_tags + `"],"fields": {%s}}`
 )
 
-type Aggregations map[string]*json.RawMessage
+type Aggregations map[string]json.RawMessage
+type AggregationSingleBucket struct {
+	Aggregations
+
+	DocCount int64 // `json:"doc_count"`
+}
+
+func (a Aggregations) Children(name string) (*AggregationSingleBucket, bool) {
+	if raw, found := a[name]; found {
+		agg := new(AggregationSingleBucket)
+		if raw == nil {
+			return agg, true
+		}
+		if err := json.Unmarshal(raw, agg); err == nil {
+			return agg, true
+		}
+	}
+	return nil, false
+}
 
 type Es interface {
 	Init()

+ 1 - 1
es/esv1.go

@@ -1254,7 +1254,7 @@ func (e *EsV1) GetAggs(index, itype, query string) (aggs Aggregations, count int
 		if searchResult.Aggregations != nil {
 			aggs = Aggregations{}
 			for k, v := range searchResult.Aggregations {
-				aggs[k] = v
+				aggs[k] = *v
 			}
 		}
 	}

+ 1 - 1
es/esv7.go

@@ -1065,7 +1065,7 @@ func (e *EsV7) GetAggs(index, itype, query string) (aggs Aggregations, count int
 		if searchResult.Aggregations != nil {
 			aggs = Aggregations{}
 			for k, v := range searchResult.Aggregations {
-				aggs[k] = &v
+				aggs[k] = v
 			}
 		}
 	}