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 Mixins::Inspectionable

#inspect, #text_for_inspect

Methods included from Mixins::BlockEvaluation

#evaluate

Methods included from Mixins::Clonable

#==, #clone

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 }
  raise "The 'include_count' parameter was removed in filter aggregations" if extra_params.has_key? :include_count
  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

Instance Method Details

#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 compact && _subaggregations.empty?
    count
  else
    raise "Compact is not a valid parameter on a subaggregated 'filter' aggregation" if compact
    body = { 'count' => count }
    body.merge! parse_subaggregations(response)
    body
  end
end