class LogStash::Outputs::Azuresearch
Public Instance Methods
flush(events, close=false)
click to toggle source
called from Stud::Buffer#buffer_flush when there are events to flush
# File lib/logstash/outputs/azuresearch.rb, line 67 def flush (events, close=false) documents = [] #this is the array of hashes to add Azure search events.each do |event| document = {} event_hash = event.to_hash() ## Check if event contains primary item that should be stored as ## primary key in Azure Search if not event_hash.include?(@primary_key_in_event) $logger.warn( "The event does not contain primary item!!: " + (event_hash.to_json).to_s) next end @column_names.each_with_index do|k, i| ikey = @key_names[i] ival = event_hash.include?(ikey) ? event_hash[ikey] : '' document[k] = ival end documents.push(document) end ## Skip in case there are no candidate documents to deliver if documents.length < 1 return end begin @client.add_documents(@search_index, documents) rescue RestClient::ExceptionWithResponse => rcex exdict = JSON.parse(rcex.response) $logger.error("RestClient Error: '#{rcex.response}', data=>" + (documents.to_json).to_s) rescue => ex $logger.error( "Error: '#{ex}'" + ", data=>" + (documents.to_json).to_s) end end
receive(event)
click to toggle source
# File lib/logstash/outputs/azuresearch.rb, line 60 def receive(event) # Simply save an event for later delivery buffer_receive(event) end
register()
click to toggle source
# File lib/logstash/outputs/azuresearch.rb, line 37 def register require_relative 'azuresearch/client' ## Configure if @key_names.length < 1 @key_names = @column_names end raise ArgumentError, 'NOT match keys number: column_names and key_names' \ if @key_names.length != @column_names.length @primary_key_in_event = @key_names[0] ## Initialize Azure Search client Instance @client=AzureSearch::Client::new( @endpoint, @api_key ) buffer_initialize( :max_items => @flush_items, :max_interval => @flush_interval_time, :logger => @logger ) end