Class: Elasticated::HistogramAggregation
- Inherits:
-
Aggregation
- Object
- Aggregation
- Elasticated::HistogramAggregation
- Includes:
- Subaggregated
- Defined in:
- lib/elasticated/aggregations/histogram_aggregation.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#interval ⇒ Object
Returns the value of attribute interval.
Attributes included from Subaggregated
Attributes inherited from Aggregation
#alias_name, #extra_params, #field
Instance Method Summary collapse
- #build ⇒ Object
- #default_name ⇒ Object
-
#initialize(field, interval, opts = {}, &block) ⇒ HistogramAggregation
constructor
A new instance of HistogramAggregation.
- #parse(response) ⇒ Object
Methods included from Subaggregated
Methods inherited from Aggregation
Methods included from Mixins::Inspectionable
Methods included from Mixins::BlockEvaluation
Methods included from Mixins::Clonable
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
#interval ⇒ Object
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
#build ⇒ Object
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_name ⇒ Object
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 |