Class: Elasticated::FilterAggregation

Inherits:
Aggregation show all
Includes:
Subaggregated
Defined in:
lib/elasticated/aggregations/filter_aggregation.rb

Instance Attribute Summary collapse

Attributes included from Subaggregated

#_subaggregations

Attributes inherited from Aggregation

#alias_name, #extra_params, #field

Instance Method Summary collapse

Methods included from Subaggregated

#initialize_subaggregations

Methods inherited from Aggregation

#name, #original_name

Methods included from Clonable

#==, #clone

Methods included from BlockEvaluation

#evaluate

Constructor Details

#initialize(filter_name, *args, &block) ⇒ FilterAggregation

Returns a new instance of FilterAggregation.



7
8
9
10
11
12
13
# File 'lib/elasticated/aggregations/filter_aggregation.rb', line 7

def initialize(filter_name, *args, &block)
  self._filter_name  = filter_name
  super
  self.compact       = extra_params.delete(:compact) { false }
  self.include_count = extra_params.delete(:include_count) { true }
  initialize_subaggregations FilterAggregationEvaluator.new, &block
end

Instance Attribute Details

#_evaluatorObject

Returns the value of attribute _evaluator.



5
6
7
# File 'lib/elasticated/aggregations/filter_aggregation.rb', line 5

def _evaluator
  @_evaluator
end

#_filter_nameObject

Returns the value of attribute _filter_name.



5
6
7
# File 'lib/elasticated/aggregations/filter_aggregation.rb', line 5

def _filter_name
  @_filter_name
end

#compactObject

Returns the value of attribute compact.



5
6
7
# File 'lib/elasticated/aggregations/filter_aggregation.rb', line 5

def compact
  @compact
end

#include_countObject

Returns the value of attribute include_count.



5
6
7
# File 'lib/elasticated/aggregations/filter_aggregation.rb', line 5

def include_count
  @include_count
end

Instance Method Details

#accept_visitor(visitor) ⇒ Object



39
40
41
# File 'lib/elasticated/aggregations/filter_aggregation.rb', line 39

def accept_visitor(visitor)
  visitor.visit_filter_aggregation(self)
end

#buildObject



19
20
21
22
23
24
25
# File 'lib/elasticated/aggregations/filter_aggregation.rb', line 19

def build
  # _subaggregations is a FilterAggregationEvaluator, so...
  conditions = _subaggregations.build_conditions
  body = { filter: conditions }
  body.merge! build_subaggregations
  body
end

#default_nameObject



15
16
17
# File 'lib/elasticated/aggregations/filter_aggregation.rb', line 15

def default_name
  _filter_name
end

#parse(response) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/elasticated/aggregations/filter_aggregation.rb', line 27

def parse(response)
  count = response['doc_count']

  if _subaggregations.empty?
    compact ? count : { 'count' => count }
  else
    parse_subaggregations(response).tap do |h|
      h['count'] = count if include_count
    end
  end
end