-
Notifications
You must be signed in to change notification settings - Fork 1
/
date_histogram_aggregation_bucket.go
60 lines (53 loc) · 1.86 KB
/
date_histogram_aggregation_bucket.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package models
import (
"time"
)
// DateHistogramAggregationResponse represents the response from an Elasticsearch date histogram aggregation
type DateHistogramAggregationResponse struct {
Aggregations struct {
ChangesOverTime struct {
Buckets []RawDateHistogramAggregationBucket `json:"buckets"`
} `json:"changes_over_time"`
} `json:"aggregations"`
}
// DateHistogramAggregationBucket represents a bucket from an Elasticsearch date histogram aggregation
type DateHistogramAggregationBucket struct {
Key string `json:"key"`
DocCount int `json:"doc_count"`
MaxModifiedDts time.Time `json:"max_modified_dts"`
MinModifiedDts time.Time `json:"min_modified_dts"`
}
// NewDateHistogramAggregationBucketFromRaw creates a new
// DateHistogramAggregationBucket object from the given raw bucket
func NewDateHistogramAggregationBucketFromRaw(rawBucket *RawDateHistogramAggregationBucket) (
*DateHistogramAggregationBucket,
error,
) {
maxDts, err := time.Parse(time.RFC3339, rawBucket.MaxModifiedDts.ValueAsString)
if err != nil {
return nil, err
}
minDts, err := time.Parse(time.RFC3339, rawBucket.MinModifiedDts.ValueAsString)
if err != nil {
return nil, err
}
return &DateHistogramAggregationBucket{
Key: rawBucket.Key,
DocCount: rawBucket.DocCount,
MaxModifiedDts: maxDts,
MinModifiedDts: minDts,
}, nil
}
// RawDateHistogramAggregationBucket represents a raw bucket from an Elasticsearch date histogram aggregation
type RawDateHistogramAggregationBucket struct {
Key string `json:"key"`
DocCount int `json:"doc_count"`
MaxModifiedDts struct {
Value float64 `json:"value"`
ValueAsString string `json:"value_as_string"`
} `json:"max_modified_dts"`
MinModifiedDts struct {
Value float64 `json:"value"`
ValueAsString string `json:"value_as_string"`
} `json:"min_modified_dts"`
}