Class: Elasticated::RangeAggregation
- Inherits:
-
Aggregation
- Object
- Aggregation
- Elasticated::RangeAggregation
- Includes:
- Subaggregated
- Defined in:
- lib/elasticated/aggregations/range_aggregation.rb
Instance Attribute Summary collapse
-
#_conditions ⇒ Object
Returns the value of attribute _conditions.
-
#compact ⇒ Object
Returns the value of attribute compact.
Attributes included from Subaggregated
Attributes inherited from Aggregation
#alias_name, #extra_params, #field
Instance Method Summary collapse
- #build ⇒ Object
- #default_name ⇒ Object
-
#initialize(field, *args, &block) ⇒ RangeAggregation
constructor
A new instance of RangeAggregation.
- #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, *args, &block) ⇒ RangeAggregation
7 8 9 10 11 12 |
# File 'lib/elasticated/aggregations/range_aggregation.rb', line 7 def initialize(field, *args, &block) super self.compact = extra_params.delete(:compact) { false } raise "The 'include_count' parameter was removed in range aggregations" if extra_params.has_key? :include_count initialize_subaggregations RangeAggregationEvaluator.new, &block end |
Instance Attribute Details
#_conditions ⇒ Object
Returns the value of attribute _conditions.
5 6 7 |
# File 'lib/elasticated/aggregations/range_aggregation.rb', line 5 def _conditions @_conditions end |
#compact ⇒ Object
Returns the value of attribute compact.
5 6 7 |
# File 'lib/elasticated/aggregations/range_aggregation.rb', line 5 def compact @compact end |
Instance Method Details
#build ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/elasticated/aggregations/range_aggregation.rb', line 18 def build # _subaggregations is a RangeAggregationEvaluator, so... ranges = _subaggregations.build_ranges body_struct = { field: field, keyed: true, ranges: ranges } body_struct.merge! extra_params body = { range: body_struct } body.merge! build_subaggregations body end |
#default_name ⇒ Object
14 15 16 |
# File 'lib/elasticated/aggregations/range_aggregation.rb', line 14 def default_name "range_over_#{field}" end |
#parse(response) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/elasticated/aggregations/range_aggregation.rb', line 28 def parse(response) response['buckets'].each_with_object({}) do |(key_name, values), hash| count = values['doc_count'] hash[key_name] = if compact && _subaggregations.empty? count else raise "Compact is not a valid parameter on a subaggregated 'range' aggregation" if compact body = { 'count' => count } body.merge! parse_subaggregations(values) body end end end |