summaryrefslogtreecommitdiffstats
path: root/vendor/gopkg.in/olivere/elastic.v5/search_aggs.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gopkg.in/olivere/elastic.v5/search_aggs.go')
-rw-r--r--vendor/gopkg.in/olivere/elastic.v5/search_aggs.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/vendor/gopkg.in/olivere/elastic.v5/search_aggs.go b/vendor/gopkg.in/olivere/elastic.v5/search_aggs.go
index 999a57d60..cc4921aeb 100644
--- a/vendor/gopkg.in/olivere/elastic.v5/search_aggs.go
+++ b/vendor/gopkg.in/olivere/elastic.v5/search_aggs.go
@@ -459,6 +459,7 @@ func (a Aggregations) Histogram(name string) (*AggregationBucketHistogramItems,
}
// DateHistogram returns date histogram aggregation results.
+//
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-bucket-datehistogram-aggregation.html
func (a Aggregations) DateHistogram(name string) (*AggregationBucketHistogramItems, bool) {
if raw, found := a[name]; found {
@@ -473,6 +474,22 @@ func (a Aggregations) DateHistogram(name string) (*AggregationBucketHistogramIte
return nil, false
}
+// KeyedDateHistogram returns date histogram aggregation results for keyed responses.
+//
+// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-datehistogram-aggregation.html#_keyed_response_3
+func (a Aggregations) KeyedDateHistogram(name string) (*AggregationBucketKeyedHistogramItems, bool) {
+ if raw, found := a[name]; found {
+ agg := new(AggregationBucketKeyedHistogramItems)
+ if raw == nil {
+ return agg, true
+ }
+ if err := json.Unmarshal(*raw, agg); err == nil {
+ return agg, true
+ }
+ }
+ return nil, false
+}
+
// GeoBounds returns geo-bounds aggregation results.
// See: https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-aggregations-metrics-geobounds-aggregation.html
func (a Aggregations) GeoBounds(name string) (*AggregationGeoBoundsMetric, bool) {
@@ -1332,6 +1349,31 @@ func (a *AggregationBucketHistogramItems) UnmarshalJSON(data []byte) error {
return nil
}
+// AggregationBucketKeyedHistogramItems is a bucket aggregation that is returned
+// with a (keyed) date histogram aggregation.
+type AggregationBucketKeyedHistogramItems struct {
+ Aggregations
+
+ Buckets map[string]*AggregationBucketHistogramItem //`json:"buckets"`
+ Meta map[string]interface{} // `json:"meta,omitempty"`
+}
+
+// UnmarshalJSON decodes JSON data and initializes an AggregationBucketKeyedHistogramItems structure.
+func (a *AggregationBucketKeyedHistogramItems) UnmarshalJSON(data []byte) error {
+ var aggs map[string]*json.RawMessage
+ if err := json.Unmarshal(data, &aggs); err != nil {
+ return err
+ }
+ if v, ok := aggs["buckets"]; ok && v != nil {
+ json.Unmarshal(*v, &a.Buckets)
+ }
+ if v, ok := aggs["meta"]; ok && v != nil {
+ json.Unmarshal(*v, &a.Meta)
+ }
+ a.Aggregations = aggs
+ return nil
+}
+
// AggregationBucketHistogramItem is a single bucket of an AggregationBucketHistogramItems structure.
type AggregationBucketHistogramItem struct {
Aggregations