Class: Elasticated::HistogramAggregation

Inherits:
Aggregation show all
Includes:
Subaggregated
Defined in:
lib/elasticated/aggregations/histogram_aggregation.rb

Instance Attribute Summary collapse

Attributes included from Subaggregated

#_subaggregations

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 Mixins::Inspectionable

#inspect, #text_for_inspect

Methods included from Mixins::BlockEvaluation

#evaluate

Methods included from Mixins::Clonable

#==, #clone

Constructor Details

#initialize(field, interval, opts = {}, &block) ⇒ HistogramAggregation

Returns a new instance of HistogramAggregation.



7
8
9
10
11
# File 'lib/elasticated/aggregations/histogram_aggregation.rb', line 7

def initialize(field, interval, opts={}, &block)
  self.interval = interval
  super
  initialize_subaggregations &block
end

Instance Attribute Details

#intervalObject

Returns the value of attribute interval.



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

def interval
  @interval
end

Instance Method Details

#buildObject



17
18
19
20
21
22
23
# File 'lib/elasticated/aggregations/histogram_aggregation.rb', line 17

def build
  terms = { field: field, interval: interval }
  terms.merge! extra_params
  aggregation_struct = { histogram: terms }
  aggregation_struct.merge! build_subaggregations
  aggregation_struct
end

#default_nameObject



13
14
15
# File 'lib/elasticated/aggregations/histogram_aggregation.rb', line 13

def default_name
  "group_by_#{field}"
end

#parse(response) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/elasticated/aggregations/histogram_aggregation.rb', line 25

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