Class: LogStash::Filters::ElasticsearchClient
- Inherits:
-
Object
- Object
- LogStash::Filters::ElasticsearchClient
- Defined in:
- lib/logstash/filters/elasticsearch/client.rb
Constant Summary collapse
- BUILD_FLAVOR_SERVERLESS =
'serverless'.freeze
- DEFAULT_EAV_HEADER =
{ "Elastic-Api-Version" => "2023-10-31" }.freeze
- INTERNAL_ORIGIN_HEADER =
{ 'x-elastic-product-origin' => 'logstash-filter-elasticsearch'}.freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #build_flavor ⇒ Object
- #es_version ⇒ Object
- #esql_query(params = {}) ⇒ Object
- #info ⇒ Object
-
#initialize(logger, hosts, options = {}) ⇒ ElasticsearchClient
constructor
A new instance of ElasticsearchClient.
- #search(params = {}) ⇒ Object
- #serverless? ⇒ Boolean
Constructor Details
#initialize(logger, hosts, options = {}) ⇒ ElasticsearchClient
Returns a new instance of ElasticsearchClient.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/logstash/filters/elasticsearch/client.rb', line 16 def initialize(logger, hosts, = {}) user = .fetch(:user, nil) password = .fetch(:password, nil) api_key = .fetch(:api_key, nil) proxy = .fetch(:proxy, nil) user_agent = [:user_agent] custom_headers = [:custom_headers] = { } [:headers] = .fetch(:serverless, false) ? DEFAULT_EAV_HEADER.dup : {} [:headers].merge!(setup_basic_auth(user, password)) [:headers].merge!(setup_api_key(api_key)) [:headers].merge!({ 'user-agent' => "#{user_agent}" }) [:headers].merge!(INTERNAL_ORIGIN_HEADER) [:headers].merge!(custom_headers) unless custom_headers.empty? [:pool_max] = 1000 [:pool_max_per_route] = 100 logger.warn "Supplied proxy setting (proxy => '') has no effect" if @proxy.eql?('') [:proxy] = proxy.to_s if proxy && !proxy.eql?('') = .fetch(:ssl, { :enabled => false }) ssl_enabled = .fetch(:enabled, false) hosts = setup_hosts(hosts, ssl_enabled) = { hosts: hosts, transport_class: ::Elastic::Transport::Transport::HTTP::Manticore, transport_options: , ssl: , retry_on_failure: [:retry_on_failure], retry_on_status: [:retry_on_status] } logger.info("New ElasticSearch filter client", :hosts => hosts) @client = ::Elasticsearch::Client.new() end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
10 11 12 |
# File 'lib/logstash/filters/elasticsearch/client.rb', line 10 def client @client end |
Instance Method Details
#build_flavor ⇒ Object
73 74 75 |
# File 'lib/logstash/filters/elasticsearch/client.rb', line 73 def build_flavor @build_flavor ||= info&.dig('version', 'build_flavor') end |
#es_version ⇒ Object
69 70 71 |
# File 'lib/logstash/filters/elasticsearch/client.rb', line 69 def es_version info&.dig('version', 'number') end |
#esql_query(params = {}) ⇒ Object
61 62 63 |
# File 'lib/logstash/filters/elasticsearch/client.rb', line 61 def esql_query(params={}) @client.esql.query(params) end |
#info ⇒ Object
65 66 67 |
# File 'lib/logstash/filters/elasticsearch/client.rb', line 65 def info @client.info end |
#search(params = {}) ⇒ Object
57 58 59 |
# File 'lib/logstash/filters/elasticsearch/client.rb', line 57 def search(params={}) @client.search(params) end |
#serverless? ⇒ Boolean
77 78 79 |
# File 'lib/logstash/filters/elasticsearch/client.rb', line 77 def serverless? @is_serverless ||= (build_flavor == BUILD_FLAVOR_SERVERLESS) end |