Class: Elasticated::TopHitsAggregation

Inherits:
Aggregation show all
Defined in:
lib/elasticated/aggregations/top_hits_aggregation.rb

Instance Attribute Summary collapse

Attributes inherited from Aggregation

#alias_name, #extra_params, #field

Instance Method Summary collapse

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(name, *args, &block) ⇒ TopHitsAggregation

Returns a new instance of TopHitsAggregation.



6
7
8
9
10
# File 'lib/elasticated/aggregations/top_hits_aggregation.rb', line 6

def initialize(name, *args, &block)
  super
  self.query = Query.new
  query.evaluate block
end

Instance Attribute Details

#queryObject

Returns the value of attribute query.



4
5
6
# File 'lib/elasticated/aggregations/top_hits_aggregation.rb', line 4

def query
  @query
end

Instance Method Details

#buildObject



12
13
14
# File 'lib/elasticated/aggregations/top_hits_aggregation.rb', line 12

def build
  { top_hits: query.build_for_top_hits }
end

#parse(response) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/elasticated/aggregations/top_hits_aggregation.rb', line 16

def parse(response)
  # total = response['hits']['total']
  # max_score = response['hits']['max_score']
  # hits = response['hits']['hits'].map{ |hit| Document.parse hit }
  # HitsInfo.new total, max_score, hits
  response['hits']['hits'].map{ |hit| Document.parse hit }
end