lib/elastics/class_proxy/templates/search.rb in elastics-client-1.1.11 vs lib/elastics/class_proxy/templates/search.rb in elastics-client-1.2.0

- old
+ new

@@ -6,11 +6,11 @@ def define_search(name, source, source_vars=nil) args = Utils.parse_source(source) send :define_template, Template::Search, name, args, source_vars end - # http://www.elasticsearch.org/guide/reference/api/multi-search.html + # https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html # requests can be an array of arrays: [[:template1, variable_hash1], [template2, variable_hash2]] # or a hash {:template1 => variable_hash1, template2 => variable_hash2} # The variables are an hash of variables that will be used to render the msearch template # the array of result is at <result>.responses def multi_search(requests, *variables) @@ -32,36 +32,33 @@ end es_response end end - # implements search_type=scan (http://www.elasticsearch.org/guide/reference/api/search/search-type.html) + # implements search_type=scan (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-type.html#scan) def scan_search(template, *vars, &block) user_raw_result = vars.any?{|v| v[:raw_result]} - scroll = '5m' - search_vars = Vars.new({:params => { :search_type => 'scan', - :scroll => scroll, - :size => 50 }, - :raw_result => true}, *vars) - search_temp = template.is_a?(Elastics::Template) ? template : templates[template] + scroll = '5m' + search_vars = Vars.new({:params => { :search_type => 'scan', + :scroll => scroll, + :size => 50 }, + :raw_result => true}, *vars) + search_temp = template.is_a?(Elastics::Template) ? template : templates[template] - scroll_vars = Vars.new({:params => { :scroll => scroll }, - :raw_result => true}, variables, *vars) - scroll_temp = Elastics::Template.new( :get, - '/_search/scroll', - nil, - scroll_vars ) - search_res = search_temp.render search_vars - scroll_id = search_res['_scroll_id'] + scroll_vars = Vars.new({:params => { :scroll => scroll }, + :raw_result => true}, variables, *vars) + scroll_temp = Elastics::Template.new( :get, '/_search/scroll', nil, scroll_vars ) + search_res = search_temp.render search_vars + scroll_id = search_res['_scroll_id'] while (result = scroll_temp.render(:data => scroll_id)) do break if result['hits']['hits'].empty? scroll_id = result['_scroll_id'] result.variables[:raw_result] = user_raw_result block.call result.to_elastics_result(force=true) end end - # implements search_type=count (http://www.elasticsearch.org/guide/reference/api/search/search-type.html) + # implements search_type=count (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-type.html#count) def count_search(template, *vars) template = template.is_a?(Elastics::Template) ? template : templates[template] template.render Vars.new({:params => {:search_type => 'count'}, :raw_result => true}, *vars) end