Class: Elasticated::Results

Inherits:
Array
  • Object
show all
Defined in:
lib/elasticated/results.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#aggregationsObject

Returns the value of attribute aggregations.



30
31
32
# File 'lib/elasticated/results.rb', line 30

def aggregations
  @aggregations
end

#documentsObject

Returns the value of attribute documents.



30
31
32
# File 'lib/elasticated/results.rb', line 30

def documents
  @documents
end

#hitsObject

methods: total, max_score



29
30
31
# File 'lib/elasticated/results.rb', line 29

def hits
  @hits
end

#shardsObject

methods: total, successful, failed



28
29
30
# File 'lib/elasticated/results.rb', line 28

def shards
  @shards
end

#timed_outObject

Returns the value of attribute timed_out.



27
28
29
# File 'lib/elasticated/results.rb', line 27

def timed_out
  @timed_out
end

#tookObject

Returns the value of attribute took.



27
28
29
# File 'lib/elasticated/results.rb', line 27

def took
  @took
end

Class Method Details

.from_elasticsearch_response(elasticsearch_response, query = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/elasticated/results.rb', line 8

def self.from_elasticsearch_response(elasticsearch_response, query=nil)
  documents = elasticsearch_response['hits']['hits'].map{ |hit| Document.from_elasticsearch_hit hit }
  results = new documents
  results.documents = documents
  # cluster metadata
  results.took = elasticsearch_response['took']
  results.timed_out = elasticsearch_response['timed_out']
  # shards metadata
  shards = elasticsearch_response['_shards']
  results.shards = ShardsInfo.new shards['total'], shards['successful'], shards['failed']
  # search metadata
  hits = elasticsearch_response['hits']
  results.hits = HitsInfo.new hits['total'], hits['max_score']
  # aggregations results
  aggregations = elasticsearch_response['aggregations']
  results.aggregations = query.parse_aggregations aggregations if query && aggregations
  results
end

Instance Method Details

#append_results_from(elasticsearch_response) ⇒ Object



32
33
34
35
36
# File 'lib/elasticated/results.rb', line 32

def append_results_from(elasticsearch_response)
  elasticsearch_response['hits']['hits'].each do |hit|
    documents.push Document.from_elasticsearch_hit hit
  end
end

#sourcesObject



38
39
40
# File 'lib/elasticated/results.rb', line 38

def sources
  documents.map &:source
end