Module: Elastic::Dsl::MetricBuilder

Included in:
ResultComposer, Query
Defined in:
lib/elastic/dsl/metric_builder.rb

Instance Method Summary collapse

Instance Method Details

#average(_field, _options = {}) ⇒ Object



3
4
5
# File 'lib/elastic/dsl/metric_builder.rb', line 3

def average(_field, _options = {})
  aggregate_metric(Elastic::Nodes::Agg::Average, _field, _options, 'avg_%s')
end

#closing(_field, _options = {}) ⇒ Object

Raises:

  • (ArgumentError)


32
33
34
35
36
37
38
39
# File 'lib/elastic/dsl/metric_builder.rb', line 32

def closing(_field, _options = {})
  by = _options.delete :by
  raise ArgumentError, 'must provide a sorting column' if by.nil?

  aggregate_metric(Elastic::Nodes::Agg::Top, _field, _options, 'close_%s') do |node|
    node.add_sort(by, order: :desc)
  end
end

#maximum(_field, _options = {}) ⇒ Object



15
16
17
# File 'lib/elastic/dsl/metric_builder.rb', line 15

def maximum(_field, _options = {})
  aggregate_metric(Elastic::Nodes::Agg::Maximum, _field, _options, 'max_%s')
end

#minimum(_field, _options = {}) ⇒ Object



11
12
13
# File 'lib/elastic/dsl/metric_builder.rb', line 11

def minimum(_field, _options = {})
  aggregate_metric(Elastic::Nodes::Agg::Minimum, _field, _options, 'min_%s')
end

#opening(_field, _options = {}) ⇒ Object

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
# File 'lib/elastic/dsl/metric_builder.rb', line 23

def opening(_field, _options = {})
  by = _options.delete :by
  raise ArgumentError, 'must provide a sorting column' if by.nil?

  aggregate_metric(Elastic::Nodes::Agg::Top, _field, _options, 'open_%s') do |node|
    node.add_sort(by, order: :asc)
  end
end

#stats(_field, _options = {}) ⇒ Object



19
20
21
# File 'lib/elastic/dsl/metric_builder.rb', line 19

def stats(_field, _options = {})
  aggregate_metric(Elastic::Nodes::Agg::Stats, _field, _options, '%s_stats')
end

#sum(_field, _options = {}) ⇒ Object



7
8
9
# File 'lib/elastic/dsl/metric_builder.rb', line 7

def sum(_field, _options = {})
  aggregate_metric(Elastic::Nodes::Agg::Sum, _field, _options, 'sum_%s')
end