@@ -394,13 +394,22 @@ func (s *SearchService) Do() (*SearchResult, error) {
394
394
}
395
395
396
396
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
404
413
}
405
414
406
415
type SearchHits struct {
@@ -501,56 +510,7 @@ type searchFacetEntry struct {
501
510
Mean float64 `json:"mean,omitempty"`
502
511
}
503
512
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)
554
514
555
515
// Highlighting
556
516
0 commit comments