Class: Elasticated::GroupAggregation
- Inherits:
-
TermsAggregation
- Object
- Aggregation
- TermsAggregation
- Elasticated::GroupAggregation
- Includes:
- Subaggregated
- Defined in:
- lib/elasticated/aggregations/group_aggregation.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#compact ⇒ Object
Returns the value of attribute compact.
-
#include_count ⇒ Object
Returns the value of attribute include_count.
Attributes included from Subaggregated
Attributes inherited from TermsAggregation
#order_field, #order_method, #size
Attributes inherited from Aggregation
#alias_name, #extra_params, #field
Instance Method Summary collapse
- #build ⇒ Object
- #default_name ⇒ Object
-
#initialize(field, *args, &block) ⇒ GroupAggregation
constructor
A new instance of GroupAggregation.
- #parse(response) ⇒ Object
Methods included from Subaggregated
Methods inherited from Aggregation
Methods included from Clonable
Methods included from BlockEvaluation
Constructor Details
#initialize(field, *args, &block) ⇒ GroupAggregation
Returns a new instance of GroupAggregation.
7 8 9 10 11 12 |
# File 'lib/elasticated/aggregations/group_aggregation.rb', line 7 def initialize(field, *args, &block) super self.compact = extra_params.delete(:compact) { false } self.include_count = extra_params.delete(:include_count) { true } initialize_subaggregations &block end |
Instance Attribute Details
#compact ⇒ Object
Returns the value of attribute compact.
5 6 7 |
# File 'lib/elasticated/aggregations/group_aggregation.rb', line 5 def compact @compact end |
#include_count ⇒ Object
Returns the value of attribute include_count.
5 6 7 |
# File 'lib/elasticated/aggregations/group_aggregation.rb', line 5 def include_count @include_count end |
Instance Method Details
#build ⇒ Object
18 19 20 |
# File 'lib/elasticated/aggregations/group_aggregation.rb', line 18 def build super.merge build_subaggregations end |
#default_name ⇒ Object
14 15 16 |
# File 'lib/elasticated/aggregations/group_aggregation.rb', line 14 def default_name "group_by_#{field}" end |
#parse(response) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/elasticated/aggregations/group_aggregation.rb', line 22 def parse(response) response['buckets'].each_with_object({}) do |bucket, hash| count = bucket['doc_count'] hash[bucket['key']] = if _subaggregations.empty? compact ? count : { 'count' => count } else parse_subaggregations(bucket).tap do |h| h['count'] = count if include_count end end end end |