Class: Elasticated::SafeDateHistogramAggregation
- Inherits:
-
HistogramAggregation
- Object
- Aggregation
- HistogramAggregation
- Elasticated::SafeDateHistogramAggregation
- Includes:
- Subaggregated
- Defined in:
- lib/elasticated/aggregations/safe_date_histogram_aggregation.rb
Constant Summary collapse
- DEFAULT_INTERVAL =
'1d'
Instance Attribute Summary collapse
-
#compact ⇒ Object
Returns the value of attribute compact.
-
#include_count ⇒ Object
Returns the value of attribute include_count.
-
#points ⇒ Object
Returns the value of attribute points.
-
#time_zone ⇒ Object
Returns the value of attribute time_zone.
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) ⇒ SafeDateHistogramAggregation
constructor
A new instance of SafeDateHistogramAggregation.
- #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) ⇒ SafeDateHistogramAggregation
Returns a new instance of SafeDateHistogramAggregation.
9 10 11 12 13 14 15 16 17 |
# File 'lib/elasticated/aggregations/safe_date_histogram_aggregation.rb', line 9 def initialize(field, opts={}, &block) self.time_zone = opts.delete(:time_zone) self.points = opts.fetch(:points) opts.delete(:points) self.compact = opts.delete(:compact) { false } self.include_count = opts.delete(:include_count) { true } interval = opts.delete(:interval) || DEFAULT_INTERVAL super field, interval, opts, &block end |
Instance Attribute Details
#compact ⇒ Object
Returns the value of attribute compact.
7 8 9 |
# File 'lib/elasticated/aggregations/safe_date_histogram_aggregation.rb', line 7 def compact @compact end |
#include_count ⇒ Object
Returns the value of attribute include_count.
7 8 9 |
# File 'lib/elasticated/aggregations/safe_date_histogram_aggregation.rb', line 7 def include_count @include_count end |
#points ⇒ Object
Returns the value of attribute points.
7 8 9 |
# File 'lib/elasticated/aggregations/safe_date_histogram_aggregation.rb', line 7 def points @points end |
#time_zone ⇒ Object
Returns the value of attribute time_zone.
7 8 9 |
# File 'lib/elasticated/aggregations/safe_date_histogram_aggregation.rb', line 7 def time_zone @time_zone end |
Instance Method Details
#build ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/elasticated/aggregations/safe_date_histogram_aggregation.rb', line 19 def build terms = { field: field, interval: safe_interval.to_s } if time_zone terms.merge! time_zone: time_zone end terms.merge! extra_params aggregation_struct = { date_histogram: terms } aggregation_struct.merge! build_subaggregations aggregation_struct end |
#parse(response) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/elasticated/aggregations/safe_date_histogram_aggregation.rb', line 30 def parse(response) response['buckets'].each_with_object({}) do |bucket, hash| count = bucket['doc_count'] key = build_key(bucket) if _subaggregations.empty? hash[key] ||= 0 if compact hash[key] = hash[key] + count else hash[key]['count'] ||= 0 hash[key]['count'] = hash[key]['count'] + count end else parsed_subaggregations = parse_subaggregations(bucket) hash[key] = value_for(parsed_subaggregations, hash, key).tap do |h| h['count'] = count #if include_count end end end end |