Class: LogStash::Outputs::ElasticAppSearch

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/outputs/elastic_app_search.rb

Constant Summary collapse

ENGINE_WITH_SPRINTF_REGEX =
/^.*%\{.+\}.*$/

Instance Method Summary collapse

Instance Method Details

#multi_receive(events) ⇒ Object



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

def multi_receive(events)
  # because App Search has a limit of 100 documents per bulk
  events.each_slice(100) do |events|
    batch = format_batch(events)
    if @logger.trace?
      @logger.trace("Sending bulk to AppSearch", :size => batch.size, :data => batch.inspect)
    end
    index(batch)
  end
end

#registerObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/logstash/outputs/elastic_app_search.rb', line 19

def register
  if @host.nil? && @url.nil?
    raise ::LogStash::ConfigurationError.new("Please specify either \"url\" (for self-managed) or \"host\" (for SaaS).")
  elsif @host && @url
    raise ::LogStash::ConfigurationError.new("Both \"url\" or \"host\" can't be set simultaneously. Please specify either \"url\" (for self-managed) or \"host\" (for SaaS).")
  elsif @host && path_is_set?  # because path has a default value we need extra work to if the user set it
    raise ::LogStash::ConfigurationError.new("The setting \"path\" is not compatible with \"host\". Use \"path\" only with \"url\".")
  elsif @host
    @client = Elastic::AppSearch::Client.new(:host_identifier => @host, :api_key => @api_key.value)
  elsif @url
    @client = Elastic::AppSearch::Client.new(:api_endpoint => @url + @path, :api_key => @api_key.value)
  end
  check_connection! unless @engine =~ ENGINE_WITH_SPRINTF_REGEX
rescue => e
  if e.message =~ /401/
    raise ::LogStash::ConfigurationError.new("Failed to connect to App Search. Error: 401. Please check your credentials")
  elsif e.message =~ /404/
    raise ::LogStash::ConfigurationError.new("Failed to connect to App Search. Error: 404. Please check if host '#{@host}' is correct and you've created an engine with name '#{@engine}'")
  else
    raise ::LogStash::ConfigurationError.new("Failed to connect to App Search. #{e.message}")
  end
end