Class: Elasticated::Results
- Inherits:
-
Object
- Object
- Elasticated::Results
- Defined in:
- lib/elasticated/results.rb
Instance Attribute Summary collapse
-
#aggregations ⇒ Object
Returns the value of attribute aggregations.
-
#documents ⇒ Object
Returns the value of attribute documents.
-
#hits ⇒ Object
methods: total, max_score.
-
#scroll_id ⇒ Object
Returns the value of attribute scroll_id.
-
#shards ⇒ Object
methods: total, successful, failed.
-
#timed_out ⇒ Object
Returns the value of attribute timed_out.
-
#took ⇒ Object
Returns the value of attribute took.
Class Method Summary collapse
- .parse(elasticsearch_response, query = nil) ⇒ Object (also: from_elasticsearch_response)
Instance Method Summary collapse
Instance Attribute Details
#aggregations ⇒ Object
Returns the value of attribute aggregations.
36 37 38 |
# File 'lib/elasticated/results.rb', line 36 def aggregations @aggregations end |
#documents ⇒ Object
Returns the value of attribute documents.
36 37 38 |
# File 'lib/elasticated/results.rb', line 36 def documents @documents end |
#hits ⇒ Object
methods: total, max_score
35 36 37 |
# File 'lib/elasticated/results.rb', line 35 def hits @hits end |
#scroll_id ⇒ Object
Returns the value of attribute scroll_id.
32 33 34 |
# File 'lib/elasticated/results.rb', line 32 def scroll_id @scroll_id end |
#shards ⇒ Object
methods: total, successful, failed
34 35 36 |
# File 'lib/elasticated/results.rb', line 34 def shards @shards end |
#timed_out ⇒ Object
Returns the value of attribute timed_out.
33 34 35 |
# File 'lib/elasticated/results.rb', line 33 def timed_out @timed_out end |
#took ⇒ Object
Returns the value of attribute took.
33 34 35 |
# File 'lib/elasticated/results.rb', line 33 def took @took end |
Class Method Details
.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 |
Instance Method Details
#append(another_results) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/elasticated/results.rb', line 38 def append(another_results) self.documents = documents + another_results.documents self.aggregations = another_results.aggregations if another_results.aggregations self.scroll_id = another_results.scroll_id if another_results.scroll_id self end |
#count ⇒ Object
57 58 59 |
# File 'lib/elasticated/results.rb', line 57 def count documents.count end |
#ids ⇒ Object
53 54 55 |
# File 'lib/elasticated/results.rb', line 53 def ids documents.map &:id end |
#sources(with_ids = true) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/elasticated/results.rb', line 45 def sources(with_ids=true) documents.map do |d| d.source.tap do |s| s[:_id] = d.id if with_ids end end end |