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.
-
#key_as_string ⇒ Object
Returns the value of attribute key_as_string.
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 Mixins::Inspectionable
Methods included from Mixins::BlockEvaluation
Methods included from Mixins::Clonable
Constructor Details
#initialize(field, *args, &block) ⇒ GroupAggregation
Returns a new instance of GroupAggregation.
7 8 9 10 11 12 13 |
# File 'lib/elasticated/aggregations/group_aggregation.rb', line 7 def initialize(field, *args, &block) super self.compact = extra_params.delete(:compact) { false } self.key_as_string = extra_params.delete(:key_as_string) { false } raise "The 'include_count' parameter was removed in group aggregations" if extra_params.has_key? :include_count 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 |
#key_as_string ⇒ Object
Returns the value of attribute key_as_string.
5 6 7 |
# File 'lib/elasticated/aggregations/group_aggregation.rb', line 5 def key_as_string @key_as_string end |
Instance Method Details
#build ⇒ Object
19 20 21 |
# File 'lib/elasticated/aggregations/group_aggregation.rb', line 19 def build super.merge build_subaggregations end |
#default_name ⇒ Object
15 16 17 |
# File 'lib/elasticated/aggregations/group_aggregation.rb', line 15 def default_name "group_by_#{field}" end |
#parse(response) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/elasticated/aggregations/group_aggregation.rb', line 23 def parse(response) response['buckets'].each_with_object({}) do |bucket, hash| key = bucket['key'] count = bucket['doc_count'] key_as_str = bucket['key_as_string'] hash[key] = if compact && _subaggregations.empty? count else raise "Compact is not a valid parameter on a subaggregated 'terms' aggregation" if compact body = { 'count' => count } body.merge! 'key_as_string' => key_as_str if key_as_string body.merge! parse_subaggregations bucket body end end end |