Class: Elasticated::GroupAggregation

Inherits:
TermsAggregation show all
Includes:
Subaggregated
Defined in:
lib/elasticated/aggregations/group_aggregation.rb

Direct Known Subclasses

SumDistinctAggregation

Instance Attribute Summary

Attributes included from Subaggregated

#_subaggregations

Attributes inherited from TermsAggregation

#order_field, #order_method, #size

Attributes inherited from Aggregation

#alias_name, #extra_params, #field

Instance Method Summary collapse

Methods included from Subaggregated

#initialize_subaggregations

Methods inherited from Aggregation

#name, #original_name

Methods included from Clonable

#==, #clone

Methods included from BlockEvaluation

#evaluate

Constructor Details

#initialize(field, *args, &block) ⇒ GroupAggregation

Returns a new instance of GroupAggregation.



5
6
7
8
# File 'lib/elasticated/aggregations/group_aggregation.rb', line 5

def initialize(field, *args, &block)
  super
  initialize_subaggregations &block
end

Instance Method Details

#buildObject



14
15
16
17
18
# File 'lib/elasticated/aggregations/group_aggregation.rb', line 14

def build
  aggregation_struct = super
  aggregation_struct.merge! build_subaggregations
  aggregation_struct
end

#default_nameObject



10
11
12
# File 'lib/elasticated/aggregations/group_aggregation.rb', line 10

def default_name
  "group_by_#{field}"
end

#parse(response) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/elasticated/aggregations/group_aggregation.rb', line 20

def parse(response)
  response['buckets'].inject({}) do |hash, bucket|
    bucket_hash = { 'count' => bucket['doc_count'] }
    bucket_hash.merge! parse_subaggregations(bucket)
    hash.merge bucket['key'] => bucket_hash
  end
end