Class: Elasticated::DateHistogramAggregation

Inherits:
HistogramAggregation show all
Includes:
Subaggregated
Defined in:
lib/elasticated/aggregations/date_histogram_aggregation.rb

Instance Attribute Summary collapse

Attributes included from Subaggregated

#_subaggregations

Attributes inherited from HistogramAggregation

#interval

Attributes inherited from Aggregation

#alias_name, #extra_params, #field

Instance Method Summary collapse

Methods included from Subaggregated

#initialize_subaggregations

Methods inherited from HistogramAggregation

#default_name

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, opts = {}, &block) ⇒ DateHistogramAggregation

Returns a new instance of DateHistogramAggregation.



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

def initialize(field, opts={}, &block)
  self.format = opts.delete(:format) || 'yyyy-MM-dd'
  interval = opts.delete(:interval) || 'day'
  super field, interval, opts, &block
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



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

def format
  @format
end

Instance Method Details

#buildObject



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

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

#parse(response) ⇒ Object



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

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_as_string'] => bucket_hash
  end
end