Method: Elasticated::Results.parse

Defined in:
lib/elasticated/results.rb

.parse(elasticsearch_response, query = nil) ⇒ Object Also known as: from_elasticsearch_response



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

def parse(elasticsearch_response, query=nil)
  documents = elasticsearch_response['hits']['hits'].map{ |hit| Document.parse hit }
  results = new
  results.documents = documents
  # scroll metadata
  results.scroll_id = elasticsearch_response['_scroll_id']
  # 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