Skip to content

Commit 17ef183

Browse files
committed
aggs: Completed aggregations of ES 1.1
Added aggregation types nested and geo_distance. Implemented access to sub-aggregations.
1 parent 1300275 commit 17ef183

9 files changed

+1017
-223
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,15 @@ Here's the current API status.
289289
* global (ok)
290290
* filter (ok)
291291
* missing (ok)
292-
* nested (missing)
292+
* nested (ok)
293293
* terms (ok)
294294
* significant terms (ok)
295295
* range (ok)
296296
* date range (ok)
297297
* ipv4 range (missing)
298298
* histogram (ok)
299299
* date histogram (ok)
300-
* geo distance (missing)
300+
* geo distance (ok)
301301
* geohash grid (missing)
302302

303303
### Scan

search.go

+17-57
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,22 @@ func (s *SearchService) Do() (*SearchResult, error) {
394394
}
395395

396396
type SearchResult struct {
397-
TookInMillis int64 `json:"took"`
398-
ScrollId string `json:"_scroll_id"`
399-
Hits *SearchHits `json:"hits"`
400-
Suggest SearchSuggest `json:"suggest"`
401-
Facets SearchFacets `json:"facets"`
402-
Aggregations SearchAggregations `json:"aggregations"`
403-
TimedOut bool `json:"timed_out"`
397+
TookInMillis int64 `json:"took"`
398+
ScrollId string `json:"_scroll_id"`
399+
Hits *SearchHits `json:"hits"`
400+
Suggest SearchSuggest `json:"suggest"`
401+
Facets SearchFacets `json:"facets"`
402+
Aggregations map[string]json.RawMessage `json:"aggregations"` // see search_aggs.go
403+
TimedOut bool `json:"timed_out"`
404+
}
405+
406+
// GetAggregation returns the aggregation with the specified name.
407+
func (res *SearchResult) GetAggregation(name string) (*SearchAggregation, bool) {
408+
agg, found := res.Aggregations[name]
409+
if !found {
410+
return nil, false
411+
}
412+
return NewSearchAggregation(name, agg), true
404413
}
405414

406415
type SearchHits struct {
@@ -501,56 +510,7 @@ type searchFacetEntry struct {
501510
Mean float64 `json:"mean,omitempty"`
502511
}
503512

504-
// Aggregations
505-
506-
type SearchAggregations map[string]*SearchAggregation
507-
508-
type SearchAggregation struct {
509-
DocCount int `json:"doc_count,omitempty"`
510-
Value float64 `json:"value,omitempty"`
511-
ValueAsString string `json:"value_as_string,omitempty"`
512-
Buckets []searchAggregationBucket `json:"buckets,omitempty"`
513-
// Number of hits for this aggregation.
514-
// This is returned e.g. with the stats aggregate.
515-
Count int `json:"count,omitempty"`
516-
// Min is either a string like "Infinity" or a float64.
517-
// This is returned e.g. with the stats aggregate.
518-
Min interface{} `json:"min,omitempty"`
519-
// Max is either a string like "-Infinity" or a float64
520-
// This is returned e.g. with the stats aggregate.
521-
Max interface{} `json:"max,omitempty"`
522-
// Avg is either a string like "-Infinity" or a float64
523-
// This is returned e.g. with the stats aggregate.
524-
Avg interface{} `json:"avg,omitempty"`
525-
// Sum is either a string like "-Infinity" or a float64
526-
// This is returned e.g. with the stats aggregate.
527-
Sum interface{} `json:"sum,omitempty"`
528-
// SumOfSquares is either a string like "-Infinity" or a float64
529-
// This is returned e.g. with the extended stats aggregate.
530-
SumOfSquares interface{} `json:"sum_of_squares,omitempty"`
531-
// Variance is either a string like "-Infinity" or a float64
532-
// This is returned e.g. with the extended stats aggregate.
533-
Variance interface{} `json:"variance,omitempty"`
534-
// StdDeviation is either a string like "-Infinity" or a float64
535-
// This is returned e.g. with the extended stats aggregate.
536-
StdDeviation interface{} `json:"std_deviation,omitempty"`
537-
538-
// TODO(oe) How do we read the results of e.g. a percentiles aggregation?
539-
// TODO(oe) How do we read the results of sub-aggregations?
540-
}
541-
542-
type searchAggregationBucket struct {
543-
Key interface{} `json:"key,omitempty"`
544-
KeyAsString *string `json:"key_as_string,omitempty"`
545-
DocCount int `json:"doc_count,omitempty"`
546-
From *float64 `json:"from,omitempty"`
547-
FromAsString *string `json:"from_as_string,omitempty"`
548-
To *float64 `json:"to,omitempty"`
549-
ToAsString *string `json:"to_as_string,omitempty"`
550-
Score *float64 `json:"score,omitempty"` // significant_terms
551-
BgCount *int `json:"bg_count,omitempty"` // significant_terms
552-
553-
}
513+
// Aggregations (see search_aggs.go)
554514

555515
// Highlighting
556516

0 commit comments

Comments
 (0)