Class: LogStash::Outputs::SolrPost
- Inherits:
-
Base
- Object
- Base
- LogStash::Outputs::SolrPost
- Includes:
- Stud::Buffer
- Defined in:
- lib/logstash/outputs/solr_post.rb
Overview
You can learn more at lucene.apache.org/solr/[the Solr home page]
Instance Method Summary collapse
Instance Method Details
#flush(events, close = false) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/logstash/outputs/solr_post.rb', line 49 def flush(events, close=false) # The documents array below is NOT being used currently, however the next version will utilize this. documents = [] #this is the array of hashes that we push to Solr as documents events.each do |event| document = event.to_hash() document["@timestamp"] = document["@timestamp"].iso8601 #make the timestamp ISO if @document_id.nil? document["id"] = UUIDTools::UUID.random_create #add a unique ID else document["id"] = event.sprintf(@document_id) #or use the one provided end url = URI.parse(@solr_url) req = Net::HTTP::Post.new(@solr_url, initheader = {'Content-Type' =>'application/json'}) req.body = '{add:{ doc:' + JSON.generate(document) + ',boost:1.0,overwrite:true,commitWithin:1000}}' res = Net::HTTP.start(url.host,url.port) do |http| http.request(req) end end rescue Exception => e @logger.warn("An error occurred while indexing: #{e.message}") end |
#receive(event) ⇒ Object
43 44 45 46 |
# File 'lib/logstash/outputs/solr_post.rb', line 43 def receive(event) buffer_receive(event) end |
#register ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/logstash/outputs/solr_post.rb', line 34 def register buffer_initialize( :max_items => @flush_size, :max_interval => @idle_flush_time, :logger => @logger ) end |