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
results.scroll_id = elasticsearch_response['_scroll_id']
results.took = elasticsearch_response['took']
results.timed_out = elasticsearch_response['timed_out']
shards = elasticsearch_response['_shards']
results.shards = ShardsInfo.new shards['total'], shards['successful'], shards['failed']
hits = elasticsearch_response['hits']
results.hits = HitsInfo.new hits['total'], hits['max_score']
aggregations = elasticsearch_response['aggregations']
results.aggregations = query.parse_aggregations aggregations if query && aggregations
results
end
|