Class: LogStash::Filters::OpenSearchClient

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/filters/opensearch/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, hosts, options = {}) ⇒ OpenSearchClient

Returns a new instance of OpenSearchClient.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/logstash/filters/opensearch/client.rb', line 11

def initialize(logger, hosts, options = {})
  ssl = options.fetch(:ssl, false)
  user = options.fetch(:user, nil)
  password = options.fetch(:password, nil)
  api_key = options.fetch(:api_key, nil)

  transport_options = {:headers => {}}
  transport_options[:headers].merge!(setup_basic_auth(user, password))
  transport_options[:headers].merge!(setup_api_key(api_key))

  hosts = hosts.map { |host| { host: host, scheme: 'https' } } if ssl
  # set ca_file even if ssl isn't on, since the host can be an https url
  ssl_options = { ssl: true, ca_file: options[:ca_file] } if options[:ca_file]
  ssl_options ||= {}

  logger.info("New OpenSearch filter client", :hosts => hosts)
  @client = ::OpenSearch::Client.new(hosts: hosts, transport_options: transport_options, :ssl => ssl_options)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/logstash/filters/opensearch/client.rb', line 9

def client
  @client
end

Instance Method Details

#search(params) ⇒ Object



30
31
32
# File 'lib/logstash/filters/opensearch/client.rb', line 30

def search(params)
  @client.search(params)
end