Class: Elasticated::HistogramAggregation
Instance Attribute Summary collapse
#_subaggregations
Attributes inherited from Aggregation
#alias_name, #extra_params, #field
Instance Method Summary
collapse
#initialize_subaggregations
Methods inherited from Aggregation
#name, #original_name
Methods included from Clonable
#==, #clone
#evaluate
Constructor Details
#initialize(field, interval, opts = {}, &block) ⇒ 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!
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
|