Skip to content

Commit 4bc5afc

Browse files
committed
Adds elastic-transport client support where opens LS-core a way to start using newer ES ruby client.
1 parent 21de990 commit 4bc5afc

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 4.1.1
2+
- Adds elastic-transport support [#191](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/191)
3+
14
## 4.1.0
25
- Added support for custom headers [#188](https://github.com/logstash-plugins/logstash-filter-elasticsearch/pull/188)
36

lib/logstash/filters/elasticsearch.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
require "monitor"
77

88
require_relative "elasticsearch/client"
9-
require_relative "elasticsearch/patches/_elasticsearch_transport_http_manticore"
109

1110
class LogStash::Filters::Elasticsearch < LogStash::Filters::Base
1211
config_name "elasticsearch"
@@ -174,6 +173,9 @@ def register
174173

175174
test_connection!
176175
setup_serverless
176+
if get_client.es_transport_client_type == "elasticsearch_transport"
177+
require_relative "elasticsearch/patches/_elasticsearch_transport_http_manticore"
178+
end
177179
end # def register
178180

179181
def filter(event)

lib/logstash/filters/elasticsearch/client.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# encoding: utf-8
22
require "elasticsearch"
33
require "base64"
4-
require "elasticsearch/transport/transport/http/manticore"
54

65

76
module LogStash
87
module Filters
98
class ElasticsearchClient
109

1110
attr_reader :client
11+
attr_reader :es_transport_client_type
1212

1313
BUILD_FLAVOR_SERVERLESS = 'serverless'.freeze
1414
DEFAULT_EAV_HEADER = { "Elastic-Api-Version" => "2023-10-31" }.freeze
@@ -44,7 +44,7 @@ def initialize(logger, hosts, options = {})
4444

4545
client_options = {
4646
hosts: hosts,
47-
transport_class: ::Elasticsearch::Transport::Transport::HTTP::Manticore,
47+
transport_class: get_transport_client_class,
4848
transport_options: transport_options,
4949
ssl: ssl_options,
5050
retry_on_failure: options[:retry_on_failure],
@@ -98,6 +98,16 @@ def setup_api_key(api_key)
9898
token = ::Base64.strict_encode64(api_key.value)
9999
{ 'Authorization' => "ApiKey #{token}" }
100100
end
101+
102+
def get_transport_client_class
103+
require "elasticsearch/transport/transport/http/manticore"
104+
es_transport_client_type = "elasticsearch_transport"
105+
::Elasticsearch::Transport::Transport::HTTP::Manticore
106+
rescue ::LoadError
107+
require "elastic/transport/transport/http/manticore"
108+
es_transport_client_type = "elastic_transport"
109+
::Elastic::Transport::Transport::HTTP::Manticore
110+
end
101111
end
102112
end
103113
end

logstash-filter-elasticsearch.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Gem::Specification.new do |s|
22

33
s.name = 'logstash-filter-elasticsearch'
4-
s.version = '4.1.0'
4+
s.version = '4.1.1'
55
s.licenses = ['Apache License (2.0)']
66
s.summary = "Copies fields from previous log events in Elasticsearch to current events "
77
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
88
s.authors = ["Elastic"]
99
s.email = 'info@elastic.co'
10-
s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
10+
s.homepage = "https://elastic.co/logstash"
1111
s.require_paths = ["lib"]
1212

1313
# Files

0 commit comments

Comments
 (0)