lib/logstash/web/lib/elasticsearch.rb in logstash-lite-0.2.20101222161646 vs lib/logstash/web/lib/elasticsearch.rb in logstash-lite-0.2.20110112115019
- old
+ new
@@ -3,15 +3,18 @@
require "logstash/namespace"
require "logstash/logging"
require "logstash/event"
module LogStash::Web; end
+
class LogStash::Web::ElasticSearch
+ public
def initialize
@logger = LogStash::Logger.new(STDOUT)
end
+ public
def search(params)
http = EventMachine::HttpRequest.new("http://localhost:9200/_search")
params[:offset] ||= 0
params[:count] ||= 20
@@ -35,11 +38,12 @@
}, # by_hour
}, # facets
"from" => params[:offset],
"size" => params[:count],
}
- #@logger.info(["ElasticSearch Query", esreq])
+
+ @logger.info("ElasticSearch Query: #{esreq.to_json}")
start_time = Time.now
req = http.get :body => esreq.to_json
req.callback do
#headers req.response_header
data = JSON.parse(req.response)
@@ -67,15 +71,15 @@
@logger.info(["Got search results",
{ :query => params[:q], :duration => data["duration"]}])
#@logger.info(data)
if req.response_header.status != 200
- @error = data["error"]
+ @error = data["error"] || req.inspect
end
yield data
end
req.errback do
- @logger.warn(["Query failed", params, req.response])
+ @logger.warn(["Query failed", params, req, req.response])
yield({ "error" => req.response })
end
end # def search
-end
+end # class LogStash::Web::ElasticSearch