Skip to content

Commit 12f5979

Browse files
committed
wip: Elasticsearch 2.0
* Convert all aggregations to pointer types.
1 parent 40491eb commit 12f5979

35 files changed

+409
-433
lines changed

search_aggs_bucket_children.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,29 @@ type ChildrenAggregation struct {
1414
meta map[string]interface{}
1515
}
1616

17-
func NewChildrenAggregation() ChildrenAggregation {
18-
a := ChildrenAggregation{
17+
func NewChildrenAggregation() *ChildrenAggregation {
18+
return &ChildrenAggregation{
1919
subAggregations: make(map[string]Aggregation),
2020
}
21-
return a
2221
}
2322

24-
func (a ChildrenAggregation) Type(typ string) ChildrenAggregation {
23+
func (a *ChildrenAggregation) Type(typ string) *ChildrenAggregation {
2524
a.typ = typ
2625
return a
2726
}
2827

29-
func (a ChildrenAggregation) SubAggregation(name string, subAggregation Aggregation) ChildrenAggregation {
28+
func (a *ChildrenAggregation) SubAggregation(name string, subAggregation Aggregation) *ChildrenAggregation {
3029
a.subAggregations[name] = subAggregation
3130
return a
3231
}
3332

3433
// Meta sets the meta data to be included in the aggregation response.
35-
func (a ChildrenAggregation) Meta(metaData map[string]interface{}) ChildrenAggregation {
34+
func (a *ChildrenAggregation) Meta(metaData map[string]interface{}) *ChildrenAggregation {
3635
a.meta = metaData
3736
return a
3837
}
3938

40-
func (a ChildrenAggregation) Source() (interface{}, error) {
39+
func (a *ChildrenAggregation) Source() (interface{}, error) {
4140
// Example:
4241
// {
4342
// "aggs" : {

search_aggs_bucket_date_histogram.go

+27-28
Original file line numberDiff line numberDiff line change
@@ -28,84 +28,83 @@ type DateHistogramAggregation struct {
2828
factor *float64
2929
}
3030

31-
func NewDateHistogramAggregation() DateHistogramAggregation {
32-
a := DateHistogramAggregation{
31+
func NewDateHistogramAggregation() *DateHistogramAggregation {
32+
return &DateHistogramAggregation{
3333
subAggregations: make(map[string]Aggregation),
3434
}
35-
return a
3635
}
3736

38-
func (a DateHistogramAggregation) Field(field string) DateHistogramAggregation {
37+
func (a *DateHistogramAggregation) Field(field string) *DateHistogramAggregation {
3938
a.field = field
4039
return a
4140
}
4241

43-
func (a DateHistogramAggregation) Script(script *Script) DateHistogramAggregation {
42+
func (a *DateHistogramAggregation) Script(script *Script) *DateHistogramAggregation {
4443
a.script = script
4544
return a
4645
}
4746

48-
func (a DateHistogramAggregation) SubAggregation(name string, subAggregation Aggregation) DateHistogramAggregation {
47+
func (a *DateHistogramAggregation) SubAggregation(name string, subAggregation Aggregation) *DateHistogramAggregation {
4948
a.subAggregations[name] = subAggregation
5049
return a
5150
}
5251

5352
// Meta sets the meta data to be included in the aggregation response.
54-
func (a DateHistogramAggregation) Meta(metaData map[string]interface{}) DateHistogramAggregation {
53+
func (a *DateHistogramAggregation) Meta(metaData map[string]interface{}) *DateHistogramAggregation {
5554
a.meta = metaData
5655
return a
5756
}
5857

5958
// Allowed values are: "year", "quarter", "month", "week", "day",
6059
// "hour", "minute". It also supports time settings like "1.5h"
6160
// (up to "w" for weeks).
62-
func (a DateHistogramAggregation) Interval(interval string) DateHistogramAggregation {
61+
func (a *DateHistogramAggregation) Interval(interval string) *DateHistogramAggregation {
6362
a.interval = interval
6463
return a
6564
}
6665

6766
// Order specifies the sort order. Valid values for order are:
6867
// "_key", "_count", a sub-aggregation name, or a sub-aggregation name
6968
// with a metric.
70-
func (a DateHistogramAggregation) Order(order string, asc bool) DateHistogramAggregation {
69+
func (a *DateHistogramAggregation) Order(order string, asc bool) *DateHistogramAggregation {
7170
a.order = order
7271
a.orderAsc = asc
7372
return a
7473
}
7574

76-
func (a DateHistogramAggregation) OrderByCount(asc bool) DateHistogramAggregation {
75+
func (a *DateHistogramAggregation) OrderByCount(asc bool) *DateHistogramAggregation {
7776
// "order" : { "_count" : "asc" }
7877
a.order = "_count"
7978
a.orderAsc = asc
8079
return a
8180
}
8281

83-
func (a DateHistogramAggregation) OrderByCountAsc() DateHistogramAggregation {
82+
func (a *DateHistogramAggregation) OrderByCountAsc() *DateHistogramAggregation {
8483
return a.OrderByCount(true)
8584
}
8685

87-
func (a DateHistogramAggregation) OrderByCountDesc() DateHistogramAggregation {
86+
func (a *DateHistogramAggregation) OrderByCountDesc() *DateHistogramAggregation {
8887
return a.OrderByCount(false)
8988
}
9089

91-
func (a DateHistogramAggregation) OrderByKey(asc bool) DateHistogramAggregation {
90+
func (a *DateHistogramAggregation) OrderByKey(asc bool) *DateHistogramAggregation {
9291
// "order" : { "_key" : "asc" }
9392
a.order = "_key"
9493
a.orderAsc = asc
9594
return a
9695
}
9796

98-
func (a DateHistogramAggregation) OrderByKeyAsc() DateHistogramAggregation {
97+
func (a *DateHistogramAggregation) OrderByKeyAsc() *DateHistogramAggregation {
9998
return a.OrderByKey(true)
10099
}
101100

102-
func (a DateHistogramAggregation) OrderByKeyDesc() DateHistogramAggregation {
101+
func (a *DateHistogramAggregation) OrderByKeyDesc() *DateHistogramAggregation {
103102
return a.OrderByKey(false)
104103
}
105104

106105
// OrderByAggregation creates a bucket ordering strategy which sorts buckets
107106
// based on a single-valued calc get.
108-
func (a DateHistogramAggregation) OrderByAggregation(aggName string, asc bool) DateHistogramAggregation {
107+
func (a *DateHistogramAggregation) OrderByAggregation(aggName string, asc bool) *DateHistogramAggregation {
109108
// {
110109
// "aggs" : {
111110
// "genders" : {
@@ -126,7 +125,7 @@ func (a DateHistogramAggregation) OrderByAggregation(aggName string, asc bool) D
126125

127126
// OrderByAggregationAndMetric creates a bucket ordering strategy which
128127
// sorts buckets based on a multi-valued calc get.
129-
func (a DateHistogramAggregation) OrderByAggregationAndMetric(aggName, metric string, asc bool) DateHistogramAggregation {
128+
func (a *DateHistogramAggregation) OrderByAggregationAndMetric(aggName, metric string, asc bool) *DateHistogramAggregation {
130129
// {
131130
// "aggs" : {
132131
// "genders" : {
@@ -145,59 +144,59 @@ func (a DateHistogramAggregation) OrderByAggregationAndMetric(aggName, metric st
145144
return a
146145
}
147146

148-
func (a DateHistogramAggregation) MinDocCount(minDocCount int64) DateHistogramAggregation {
147+
func (a *DateHistogramAggregation) MinDocCount(minDocCount int64) *DateHistogramAggregation {
149148
a.minDocCount = &minDocCount
150149
return a
151150
}
152151

153-
func (a DateHistogramAggregation) PreZone(preZone string) DateHistogramAggregation {
152+
func (a *DateHistogramAggregation) PreZone(preZone string) *DateHistogramAggregation {
154153
a.preZone = preZone
155154
return a
156155
}
157156

158-
func (a DateHistogramAggregation) PostZone(postZone string) DateHistogramAggregation {
157+
func (a *DateHistogramAggregation) PostZone(postZone string) *DateHistogramAggregation {
159158
a.postZone = postZone
160159
return a
161160
}
162161

163-
func (a DateHistogramAggregation) PreZoneAdjustLargeInterval(preZoneAdjustLargeInterval bool) DateHistogramAggregation {
162+
func (a *DateHistogramAggregation) PreZoneAdjustLargeInterval(preZoneAdjustLargeInterval bool) *DateHistogramAggregation {
164163
a.preZoneAdjustLargeInterval = &preZoneAdjustLargeInterval
165164
return a
166165
}
167166

168-
func (a DateHistogramAggregation) PreOffset(preOffset int64) DateHistogramAggregation {
167+
func (a *DateHistogramAggregation) PreOffset(preOffset int64) *DateHistogramAggregation {
169168
a.preOffset = preOffset
170169
return a
171170
}
172171

173-
func (a DateHistogramAggregation) PostOffset(postOffset int64) DateHistogramAggregation {
172+
func (a *DateHistogramAggregation) PostOffset(postOffset int64) *DateHistogramAggregation {
174173
a.postOffset = postOffset
175174
return a
176175
}
177176

178-
func (a DateHistogramAggregation) Factor(factor float64) DateHistogramAggregation {
177+
func (a *DateHistogramAggregation) Factor(factor float64) *DateHistogramAggregation {
179178
a.factor = &factor
180179
return a
181180
}
182181

183-
func (a DateHistogramAggregation) Format(format string) DateHistogramAggregation {
182+
func (a *DateHistogramAggregation) Format(format string) *DateHistogramAggregation {
184183
a.format = format
185184
return a
186185
}
187186

188187
// ExtendedBoundsMin accepts int, int64, string, or time.Time values.
189-
func (a DateHistogramAggregation) ExtendedBoundsMin(min interface{}) DateHistogramAggregation {
188+
func (a *DateHistogramAggregation) ExtendedBoundsMin(min interface{}) *DateHistogramAggregation {
190189
a.extendedBoundsMin = min
191190
return a
192191
}
193192

194193
// ExtendedBoundsMax accepts int, int64, string, or time.Time values.
195-
func (a DateHistogramAggregation) ExtendedBoundsMax(max interface{}) DateHistogramAggregation {
194+
func (a *DateHistogramAggregation) ExtendedBoundsMax(max interface{}) *DateHistogramAggregation {
196195
a.extendedBoundsMax = max
197196
return a
198197
}
199198

200-
func (a DateHistogramAggregation) Source() (interface{}, error) {
199+
func (a *DateHistogramAggregation) Source() (interface{}, error) {
201200
// Example:
202201
// {
203202
// "aggs" : {

search_aggs_bucket_date_range.go

+22-23
Original file line numberDiff line numberDiff line change
@@ -33,111 +33,110 @@ type DateRangeAggregationEntry struct {
3333
To interface{}
3434
}
3535

36-
func NewDateRangeAggregation() DateRangeAggregation {
37-
a := DateRangeAggregation{
36+
func NewDateRangeAggregation() *DateRangeAggregation {
37+
return &DateRangeAggregation{
3838
subAggregations: make(map[string]Aggregation),
3939
entries: make([]DateRangeAggregationEntry, 0),
4040
}
41-
return a
4241
}
4342

44-
func (a DateRangeAggregation) Field(field string) DateRangeAggregation {
43+
func (a *DateRangeAggregation) Field(field string) *DateRangeAggregation {
4544
a.field = field
4645
return a
4746
}
4847

49-
func (a DateRangeAggregation) Script(script *Script) DateRangeAggregation {
48+
func (a *DateRangeAggregation) Script(script *Script) *DateRangeAggregation {
5049
a.script = script
5150
return a
5251
}
5352

54-
func (a DateRangeAggregation) SubAggregation(name string, subAggregation Aggregation) DateRangeAggregation {
53+
func (a *DateRangeAggregation) SubAggregation(name string, subAggregation Aggregation) *DateRangeAggregation {
5554
a.subAggregations[name] = subAggregation
5655
return a
5756
}
5857

5958
// Meta sets the meta data to be included in the aggregation response.
60-
func (a DateRangeAggregation) Meta(metaData map[string]interface{}) DateRangeAggregation {
59+
func (a *DateRangeAggregation) Meta(metaData map[string]interface{}) *DateRangeAggregation {
6160
a.meta = metaData
6261
return a
6362
}
6463

65-
func (a DateRangeAggregation) Keyed(keyed bool) DateRangeAggregation {
64+
func (a *DateRangeAggregation) Keyed(keyed bool) *DateRangeAggregation {
6665
a.keyed = &keyed
6766
return a
6867
}
6968

70-
func (a DateRangeAggregation) Unmapped(unmapped bool) DateRangeAggregation {
69+
func (a *DateRangeAggregation) Unmapped(unmapped bool) *DateRangeAggregation {
7170
a.unmapped = &unmapped
7271
return a
7372
}
7473

75-
func (a DateRangeAggregation) Format(format string) DateRangeAggregation {
74+
func (a *DateRangeAggregation) Format(format string) *DateRangeAggregation {
7675
a.format = format
7776
return a
7877
}
7978

80-
func (a DateRangeAggregation) AddRange(from, to interface{}) DateRangeAggregation {
79+
func (a *DateRangeAggregation) AddRange(from, to interface{}) *DateRangeAggregation {
8180
a.entries = append(a.entries, DateRangeAggregationEntry{From: from, To: to})
8281
return a
8382
}
8483

85-
func (a DateRangeAggregation) AddRangeWithKey(key string, from, to interface{}) DateRangeAggregation {
84+
func (a *DateRangeAggregation) AddRangeWithKey(key string, from, to interface{}) *DateRangeAggregation {
8685
a.entries = append(a.entries, DateRangeAggregationEntry{Key: key, From: from, To: to})
8786
return a
8887
}
8988

90-
func (a DateRangeAggregation) AddUnboundedTo(from interface{}) DateRangeAggregation {
89+
func (a *DateRangeAggregation) AddUnboundedTo(from interface{}) *DateRangeAggregation {
9190
a.entries = append(a.entries, DateRangeAggregationEntry{From: from, To: nil})
9291
return a
9392
}
9493

95-
func (a DateRangeAggregation) AddUnboundedToWithKey(key string, from interface{}) DateRangeAggregation {
94+
func (a *DateRangeAggregation) AddUnboundedToWithKey(key string, from interface{}) *DateRangeAggregation {
9695
a.entries = append(a.entries, DateRangeAggregationEntry{Key: key, From: from, To: nil})
9796
return a
9897
}
9998

100-
func (a DateRangeAggregation) AddUnboundedFrom(to interface{}) DateRangeAggregation {
99+
func (a *DateRangeAggregation) AddUnboundedFrom(to interface{}) *DateRangeAggregation {
101100
a.entries = append(a.entries, DateRangeAggregationEntry{From: nil, To: to})
102101
return a
103102
}
104103

105-
func (a DateRangeAggregation) AddUnboundedFromWithKey(key string, to interface{}) DateRangeAggregation {
104+
func (a *DateRangeAggregation) AddUnboundedFromWithKey(key string, to interface{}) *DateRangeAggregation {
106105
a.entries = append(a.entries, DateRangeAggregationEntry{Key: key, From: nil, To: to})
107106
return a
108107
}
109108

110-
func (a DateRangeAggregation) Lt(to interface{}) DateRangeAggregation {
109+
func (a *DateRangeAggregation) Lt(to interface{}) *DateRangeAggregation {
111110
a.entries = append(a.entries, DateRangeAggregationEntry{From: nil, To: to})
112111
return a
113112
}
114113

115-
func (a DateRangeAggregation) LtWithKey(key string, to interface{}) DateRangeAggregation {
114+
func (a *DateRangeAggregation) LtWithKey(key string, to interface{}) *DateRangeAggregation {
116115
a.entries = append(a.entries, DateRangeAggregationEntry{Key: key, From: nil, To: to})
117116
return a
118117
}
119118

120-
func (a DateRangeAggregation) Between(from, to interface{}) DateRangeAggregation {
119+
func (a *DateRangeAggregation) Between(from, to interface{}) *DateRangeAggregation {
121120
a.entries = append(a.entries, DateRangeAggregationEntry{From: from, To: to})
122121
return a
123122
}
124123

125-
func (a DateRangeAggregation) BetweenWithKey(key string, from, to interface{}) DateRangeAggregation {
124+
func (a *DateRangeAggregation) BetweenWithKey(key string, from, to interface{}) *DateRangeAggregation {
126125
a.entries = append(a.entries, DateRangeAggregationEntry{Key: key, From: from, To: to})
127126
return a
128127
}
129128

130-
func (a DateRangeAggregation) Gt(from interface{}) DateRangeAggregation {
129+
func (a *DateRangeAggregation) Gt(from interface{}) *DateRangeAggregation {
131130
a.entries = append(a.entries, DateRangeAggregationEntry{From: from, To: nil})
132131
return a
133132
}
134133

135-
func (a DateRangeAggregation) GtWithKey(key string, from interface{}) DateRangeAggregation {
134+
func (a *DateRangeAggregation) GtWithKey(key string, from interface{}) *DateRangeAggregation {
136135
a.entries = append(a.entries, DateRangeAggregationEntry{Key: key, From: from, To: nil})
137136
return a
138137
}
139138

140-
func (a DateRangeAggregation) Source() (interface{}, error) {
139+
func (a *DateRangeAggregation) Source() (interface{}, error) {
141140
// Example:
142141
// {
143142
// "aggs" : {

search_aggs_bucket_filter.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,29 @@ type FilterAggregation struct {
1515
meta map[string]interface{}
1616
}
1717

18-
func NewFilterAggregation() FilterAggregation {
19-
a := FilterAggregation{
18+
func NewFilterAggregation() *FilterAggregation {
19+
return &FilterAggregation{
2020
subAggregations: make(map[string]Aggregation),
2121
}
22-
return a
2322
}
2423

25-
func (a FilterAggregation) SubAggregation(name string, subAggregation Aggregation) FilterAggregation {
24+
func (a *FilterAggregation) SubAggregation(name string, subAggregation Aggregation) *FilterAggregation {
2625
a.subAggregations[name] = subAggregation
2726
return a
2827
}
2928

3029
// Meta sets the meta data to be included in the aggregation response.
31-
func (a FilterAggregation) Meta(metaData map[string]interface{}) FilterAggregation {
30+
func (a *FilterAggregation) Meta(metaData map[string]interface{}) *FilterAggregation {
3231
a.meta = metaData
3332
return a
3433
}
3534

36-
func (a FilterAggregation) Filter(filter Query) FilterAggregation {
35+
func (a *FilterAggregation) Filter(filter Query) *FilterAggregation {
3736
a.filter = filter
3837
return a
3938
}
4039

41-
func (a FilterAggregation) Source() (interface{}, error) {
40+
func (a *FilterAggregation) Source() (interface{}, error) {
4241
// Example:
4342
// {
4443
// "aggs" : {

0 commit comments

Comments
 (0)