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.
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 |
# 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
#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 |
Instance Method Details
#build ⇒ Object
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 |