8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/slingshot/dsl.rb', line 8
def search(indices, options={}, &block)
if block_given?
Search::Search.new(indices, options, &block).perform
else
payload = case options
when Hash then options.to_json
when String then options
else raise ArgumentError, "Please pass a Ruby Hash or String with JSON"
end
response = Configuration.client.post( "#{Configuration.url}/#{indices}/_search", payload)
json = Yajl::Parser.parse(response.body)
results = Results::Collection.new(json, options)
end
rescue Exception => error
STDERR.puts "[REQUEST FAILED] #{error.class} #{error.http_body rescue nil}\n"
raise
ensure
end
|