|
1 | 1 | # encoding: utf-8 |
2 | 2 | require "elasticsearch" |
3 | 3 | require "base64" |
4 | | -require "elasticsearch/transport/transport/http/manticore" |
5 | 4 |
|
6 | 5 |
|
7 | 6 | module LogStash |
8 | 7 | module Filters |
9 | 8 | class ElasticsearchClient |
10 | 9 |
|
11 | 10 | attr_reader :client |
| 11 | + attr_reader :es_transport_client_type |
12 | 12 |
|
13 | 13 | BUILD_FLAVOR_SERVERLESS = 'serverless'.freeze |
14 | 14 | DEFAULT_EAV_HEADER = { "Elastic-Api-Version" => "2023-10-31" }.freeze |
@@ -44,7 +44,7 @@ def initialize(logger, hosts, options = {}) |
44 | 44 |
|
45 | 45 | client_options = { |
46 | 46 | hosts: hosts, |
47 | | - transport_class: ::Elasticsearch::Transport::Transport::HTTP::Manticore, |
| 47 | + transport_class: get_transport_client_class, |
48 | 48 | transport_options: transport_options, |
49 | 49 | ssl: ssl_options, |
50 | 50 | retry_on_failure: options[:retry_on_failure], |
@@ -98,6 +98,20 @@ def setup_api_key(api_key) |
98 | 98 | token = ::Base64.strict_encode64(api_key.value) |
99 | 99 | { 'Authorization' => "ApiKey #{token}" } |
100 | 100 | end |
| 101 | + |
| 102 | + def get_transport_client_class |
| 103 | + # LS-core includes `elasticsearch` gem. The gem is composed of two separate gems: `elasticsearch-api` and `elasticsearch-transport` |
| 104 | + # And now `elasticsearch-transport` is old, instead we have `elastic-transport`. |
| 105 | + # LS-core updated `elasticsearch` > 8: https://github.com/elastic/logstash/pull/17161 |
| 106 | + # Following source bits are for the compatibility to support both `elasticsearch-transport` and `elastic-transport` gems |
| 107 | + require "elasticsearch/transport/transport/http/manticore" |
| 108 | + es_transport_client_type = "elasticsearch_transport" |
| 109 | + ::Elasticsearch::Transport::Transport::HTTP::Manticore |
| 110 | + rescue ::LoadError |
| 111 | + require "elastic/transport/transport/http/manticore" |
| 112 | + es_transport_client_type = "elastic_transport" |
| 113 | + ::Elastic::Transport::Transport::HTTP::Manticore |
| 114 | + end |
101 | 115 | end |
102 | 116 | end |
103 | 117 | end |
0 commit comments