Module: Elasticsearch::Rails2::Searching::ClassMethods
- Defined in:
- lib/elasticsearch/rails2/searching.rb
Instance Method Summary collapse
-
#scan_all_ids(query_or_payload, options = {}) ⇒ Object
Scan and scroll all ids Useful to do a SQL query with IN(…) operator.
-
#search(query_or_payload, options = {}) ⇒ Elasticsearch::Rails2::Response
Provides a ‘search` method for the model to easily search within an index/type corresponding to the model settings.
Instance Method Details
#scan_all_ids(query_or_payload, options = {}) ⇒ Object
Scan and scroll all ids Useful to do a SQL query with IN(…) operator
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/elasticsearch/rails2/searching.rb', line 106 def scan_all_ids(query_or_payload, ={}) ids = [] scroll = [:scroll] search_response = search(query_or_payload, .update(search_type: 'scan')) response = search_response.response while response = client.scroll(scroll_id: response['_scroll_id'], scroll: scroll) and !response['hits']['hits'].empty? do response['hits']['hits'].each { |r| ids << r['_id']} end ids end |
#search(query_or_payload, options = {}) ⇒ Elasticsearch::Rails2::Response
Provides a ‘search` method for the model to easily search within an index/type corresponding to the model settings.
98 99 100 101 |
# File 'lib/elasticsearch/rails2/searching.rb', line 98 def search(query_or_payload, ={}) search = SearchRequest.new(self, query_or_payload, ) Response::Response.new(self, search) end |