-
-
Save fcheung/92d77b62eb570031823d to your computer and use it in GitHub Desktop.
tire multisearch implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Tire | |
module Search | |
class Search | |
attr_reader :types | |
end | |
class MultiSearch | |
def initialize(searches, options ={}) | |
@searches = searches | |
@options = options | |
end | |
def to_payload | |
payload = @searches.each_with_object([]) do |search, result| | |
result << {:index => search.indices, :types => search.types}.to_json | |
result << search.to_json | |
end | |
payload << "" | |
payload.join("\n") | |
end | |
def results | |
@results || (perform; @results) | |
end | |
def perform | |
response = Configuration.client.post("#{Configuration.url}/_msearch", to_payload) | |
json = MultiJson.decode(response.body) | |
@results = json['responses'].each_with_index.collect do |response_json, index| | |
Results::Collection.new(response_json, @options.merge(@searches[index].options)) | |
end | |
end | |
end | |
end | |
end |
@fcheung: Those numbers sound very interesting.
@karmi oops, I was referring to persistent connections, I didn't succeed in achieving persistent conns before that.
@romanbsd: Curb definitely does persistence connections, see the benchmark...
I was checking it with tcpdump at the time, and was observing SYN packets. Perhaps there was something different in my setup... Is curb's persistent connection handling thread safe?
Will this get rolled into Tire? For now I am gonna use the bits I need to make a multisearch request via RestClient manually until that happens.
Yes, multi search support is now available in Tire 0.5.0/master:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@romanbsd: No, Tire had support for RestClient and Curb for a long long time (karmi/retire@8010531)