Class: LogStash::Outputs::SolrHTTP

Inherits:
Base show all
Includes:
Stud::Buffer
Defined in:
lib/logstash/outputs/solr_http.rb

Overview

This output lets you index&store your logs in Solr. If you want to get started quickly you should use version 4.4 or above in schemaless mode, which will try and guess your fields automatically. To turn that on, you can use the example included in the Solr archive:

tar zxf solr-4.4.0.tgz
cd example
mv solr solr_ #back up the existing sample conf
cp -r example-schemaless/solr/ .  #put the schemaless conf in place
java -jar start.jar   #start Solr

You can learn more about Solr at <lucene.apache.org/solr/>

Constant Summary

Constants included from Config::Mixin

Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes included from Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Base

#handle, #handle_worker, #initialize, #worker_setup, #workers_not_supported

Methods included from Config::Mixin

#config_init, included

Methods inherited from Plugin

#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s

Constructor Details

This class inherits a constructor from LogStash::Outputs::Base

Instance Method Details

#flush(events, teardown = false) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/logstash/outputs/solr_http.rb', line 60

def flush(events, teardown=false)
  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
      documents.push(document)
  end

  @solr.add(documents)
  rescue Exception => e
    @logger.warn("An error occurred while indexing: #{e.message}")
end

#receive(event) ⇒ Object



54
55
56
57
# File 'lib/logstash/outputs/solr_http.rb', line 54

def receive(event)
  return unless output?(event)
  buffer_receive(event)
end

#registerObject



43
44
45
46
47
48
49
50
51
# File 'lib/logstash/outputs/solr_http.rb', line 43

def register
  require "rsolr"
  @solr = RSolr.connect :url => @solr_url
  buffer_initialize(
    :max_items => @flush_size,
    :max_interval => @idle_flush_time,
    :logger => @logger
  )
end