Module: Elastic::Nodes::Concerns::Aggregable

Included in:
Agg::DateHistogram, Agg::Terms, Search
Defined in:
lib/elastic/nodes/concerns/aggregable.rb

Instance Method Summary collapse

Instance Method Details

#aggregate(_node) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
# File 'lib/elastic/nodes/concerns/aggregable.rb', line 15

def aggregate(_node)
  raise ArgumentError, 'node must provide a name' unless _node.name
  aggs << _node
end

#aggregationsObject



11
12
13
# File 'lib/elastic/nodes/concerns/aggregable.rb', line 11

def aggregations
  @aggs.each
end

#aggregations=(_aggs) ⇒ Object



7
8
9
# File 'lib/elastic/nodes/concerns/aggregable.rb', line 7

def aggregations=(_aggs)
  @aggs = _aggs.dup.to_a
end

#cloneObject



25
26
27
28
29
# File 'lib/elastic/nodes/concerns/aggregable.rb', line 25

def clone
  node = super
  node.aggregations = aggs.map(&:clone)
  node
end

#has_aggregations?Boolean

Returns:



3
4
5
# File 'lib/elastic/nodes/concerns/aggregable.rb', line 3

def has_aggregations?
  aggs.count > 0
end

#simplifyObject



31
32
33
34
35
# File 'lib/elastic/nodes/concerns/aggregable.rb', line 31

def simplify
  node = super
  node.aggregations = aggs.map(&:simplify)
  node
end

#traverse(&_block) ⇒ Object



20
21
22
23
# File 'lib/elastic/nodes/concerns/aggregable.rb', line 20

def traverse(&_block)
  super
  aggs.each { |a| a.traverse(&_block) }
end