aggregations support
This commit is contained in:
parent
caac0b3f53
commit
c7c95eccdc
31
goes.go
31
goes.go
@ -348,3 +348,34 @@ func (r *Request) Url() string {
|
|||||||
|
|
||||||
return u.String()
|
return u.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Buckets returns list of buckets in aggregation
|
||||||
|
func (a Aggregation) Buckets() []Bucket {
|
||||||
|
result := []Bucket{}
|
||||||
|
if buckets, ok := a["buckets"]; ok {
|
||||||
|
for _, bucket := range buckets.([]interface {}) {
|
||||||
|
result = append(result, bucket.(map[string]interface{}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// Key returns key for aggregation bucket
|
||||||
|
func (b Bucket) Key() interface{} {
|
||||||
|
return b["key"]
|
||||||
|
}
|
||||||
|
|
||||||
|
// DocCount returns count of documents in this bucket
|
||||||
|
func (b Bucket) DocCount() uint64 {
|
||||||
|
return uint64(b["doc_count"].(float64))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregation returns aggregation by name from bucket
|
||||||
|
func (b Bucket) Aggregation(name string) Aggregation{
|
||||||
|
if agg, ok := b[name]; ok {
|
||||||
|
return agg.(map[string]interface{})
|
||||||
|
} else {
|
||||||
|
return Aggregation{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -82,8 +82,14 @@ type Response struct {
|
|||||||
|
|
||||||
// Scroll id for iteration
|
// Scroll id for iteration
|
||||||
ScrollId string `json:"_scroll_id"`
|
ScrollId string `json:"_scroll_id"`
|
||||||
|
|
||||||
|
Aggregations map[string]Aggregation `json:"aggregations,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Aggregation map[string]interface{}
|
||||||
|
|
||||||
|
type Bucket map[string]interface{}
|
||||||
|
|
||||||
// Represents a document to send to elasticsearch
|
// Represents a document to send to elasticsearch
|
||||||
type Document struct {
|
type Document struct {
|
||||||
// XXX : interface as we can support nil values
|
// XXX : interface as we can support nil values
|
||||||
|
Loading…
Reference in New Issue
Block a user