Class: LogStash::Search::Twitter
- Defined in:
- lib/logstash/search/twitter.rb
Instance Method Summary collapse
-
#histogram(query, field, interval = nil) {|result| ... } ⇒ Object
def search.
-
#initialize(settings = {}) ⇒ Twitter
constructor
A new instance of Twitter.
- #search(query) ⇒ Object
Methods inherited from Base
Constructor Details
Instance Method Details
#histogram(query, field, interval = nil) {|result| ... } ⇒ Object
def search
85 86 87 88 89 |
# File 'lib/logstash/search/twitter.rb', line 85 def histogram(query, field, interval=nil) # Nothing to histogram. result = LogStash::Search::FacetResult.new yield result end |
#search(query) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/logstash/search/twitter.rb', line 20 def search(query) raise "No block given for search call." if !block_given? if query.is_a?(String) query = LogStash::Search::Query.parse(query) end # TODO(sissel): only search a specific index? http = EventMachine::HttpRequest.new("http://#{@host}:#{@port}/search.json?q=#{URI.escape(query.query_string)}&rpp=#{URI.escape(query.count) rescue query.count}") @logger.info(["Query", query]) start_time = Time.now req = http.get result = LogStash::Search::Result.new req.callback do data = JSON.parse(req.response) result.duration = Time.now - start_time hits = (data["results"] || nil) rescue nil if hits.nil? or !data["error"].nil? # Use the error message if any, otherwise, return the whole # data object as json as the error message for debugging later. result. = (data["error"] rescue false) || data.to_json yield result next end hits.each do |hit| hit["@message"] = hit["text"] hit["@timestamp"] = hit["created_at"] hit.delete("text") end @logger.info(["Got search results", { :query => query.query_string, :duration => data["duration"], :result_count => hits.size }]) if req.response_header.status != 200 result. = data["error"] || req.inspect @error = data["error"] || req.inspect end # We want to yield a list of LogStash::Event objects. hits.each do |hit| result.events << LogStash::Event.new(hit) end # Total hits this search could find if not limited result.total = hits.size result.offset = 0 yield result end req.errback do @logger.warn(["Query failed", query, req, req.response]) result.duration = Time.now - start_time result. = req.response yield result end end |