Class: Elastic::Nodes::Agg::Top
Constant Summary
Concerns::Sortable::MODES, Concerns::Sortable::ORDER
Instance Attribute Summary collapse
Attributes inherited from BaseAgg
#name
Class Method Summary
collapse
Instance Method Summary
collapse
#add_sort, #reset_sorts, #sorts
Methods inherited from BaseAgg
#initialize
Methods inherited from Base
#==, #traverse
#pick_nodes, #traverse
Instance Attribute Details
#field ⇒ Object
Returns the value of attribute field.
11
12
13
|
# File 'lib/elastic/nodes/agg/top.rb', line 11
def field
@field
end
|
Class Method Details
.build(_name, _field, _options = {}) ⇒ Object
5
6
7
8
9
|
# File 'lib/elastic/nodes/agg/top.rb', line 5
def self.build(_name, _field, _options = {})
super(_name).tap do |node|
node.field = _field
end
end
|
Instance Method Details
#clone ⇒ Object
13
14
15
|
# File 'lib/elastic/nodes/agg/top.rb', line 13
def clone
prepare_clone super
end
|
#handle_result(_raw, _formatter) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/elastic/nodes/agg/top.rb', line 28
def handle_result(_raw, _formatter)
hit = _raw['hits']['hits'].first
raw_value = hit ? hit['_source'][@field.to_s] : nil
Elastic::Results::Metric.new raw_value
end
|
#render(_options = {}) ⇒ Object
21
22
23
24
25
26
|
# File 'lib/elastic/nodes/agg/top.rb', line 21
def render(_options = {})
top_hit_config = { '_source' => { 'includes' => [@field.to_s] }, 'size' => 1 }
top_hit_config['sort'] = render_sorts if registered_sorts.count > 0
{ 'top_hits' => top_hit_config }
end
|
#simplify ⇒ Object
17
18
19
|
# File 'lib/elastic/nodes/agg/top.rb', line 17
def simplify
prepare_clone super
end
|