Class: Elasticated::DateHistogramAggregation
- Inherits:
-
HistogramAggregation
- Object
- Aggregation
- HistogramAggregation
- Elasticated::DateHistogramAggregation
- Includes:
- Subaggregated
- Defined in:
- lib/elasticated/aggregations/date_histogram_aggregation.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#offset ⇒ Object
Returns the value of attribute offset.
Attributes included from Subaggregated
Attributes inherited from HistogramAggregation
Attributes inherited from Aggregation
#alias_name, #extra_params, #field
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(field, opts = {}, &block) ⇒ DateHistogramAggregation
constructor
A new instance of DateHistogramAggregation.
- #parse(response) ⇒ Object
Methods included from Subaggregated
Methods inherited from HistogramAggregation
Methods inherited from Aggregation
Methods included from Mixins::Inspectionable
Methods included from Mixins::BlockEvaluation
Methods included from Mixins::Clonable
Constructor Details
#initialize(field, opts = {}, &block) ⇒ DateHistogramAggregation
Returns a new instance of DateHistogramAggregation.
7 8 9 10 11 12 |
# 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' self.offset = opts.delete(:offset) super field, interval, opts, &block end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
5 6 7 |
# File 'lib/elasticated/aggregations/date_histogram_aggregation.rb', line 5 def format @format end |
#offset ⇒ Object
Returns the value of attribute offset.
5 6 7 |
# File 'lib/elasticated/aggregations/date_histogram_aggregation.rb', line 5 def offset @offset end |
Instance Method Details
#build ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/elasticated/aggregations/date_histogram_aggregation.rb', line 14 def build terms = { field: field, interval: interval, format: format } if offset # '1.4 style' terms.merge! pre_offset: offset terms.merge! post_offset: offset end terms.merge! extra_params aggregation_struct = { date_histogram: terms } aggregation_struct.merge! build_subaggregations aggregation_struct end |
#parse(response) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/elasticated/aggregations/date_histogram_aggregation.rb', line 26 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 |