Commit 02b15a8fd2f0cbb51a2f68e28e56ccb5c6a7a6e2
1 parent
025caf83
Exists in
master
and in
2 other branches
Removed elasticsearch dependency [skip ci]
Showing
6 changed files
with
37 additions
and
11 deletions
Show diff stats
CHANGELOG.md
... | ... | @@ -6,6 +6,7 @@ |
6 | 6 | - Raise `ArgumentError` instead of `RuntimeError` for unknown operators |
7 | 7 | - Removed mapping of `id` to `_id` with `order` option |
8 | 8 | - Removed `wordnet` option |
9 | +- Removed `elasticsearch` dependency | |
9 | 10 | - Dropped support for Ruby < 2.6 and Active Record < 5.2 |
10 | 11 | - Dropped support for NoBrainer and Cequel |
11 | 12 | - Dropped support for `faraday_middleware-aws-signers-v4` (use `faraday_middleware-aws-sigv4` instead) | ... | ... |
Gemfile
gemfiles/opensearch.gemfile
lib/searchkick.rb
1 | 1 | # dependencies |
2 | 2 | require "active_support" |
3 | 3 | require "active_support/core_ext/hash/deep_merge" |
4 | -require "elasticsearch" | |
5 | 4 | require "hashie" |
6 | 5 | |
7 | 6 | # modules |
... | ... | @@ -41,6 +40,7 @@ module Searchkick |
41 | 40 | class InvalidQueryError < Error; end |
42 | 41 | class DangerousOperation < Error; end |
43 | 42 | class ImportError < Error; end |
43 | + class ClientNotFound < Error; end | |
44 | 44 | |
45 | 45 | class << self |
46 | 46 | attr_accessor :search_method_name, :timeout, :models, :client_options, :redis, :index_prefix, :index_suffix, :queue_name, :model_options |
... | ... | @@ -58,13 +58,38 @@ module Searchkick |
58 | 58 | @client ||= begin |
59 | 59 | require "typhoeus/adapters/faraday" if defined?(Typhoeus) && Gem::Version.new(Faraday::VERSION) < Gem::Version.new("0.14.0") |
60 | 60 | |
61 | - Elasticsearch::Client.new({ | |
62 | - url: ENV["ELASTICSEARCH_URL"] || ENV["OPENSEARCH_URL"], | |
63 | - transport_options: {request: {timeout: timeout}, headers: {content_type: "application/json"}}, | |
64 | - retry_on_failure: 2 | |
65 | - }.deep_merge(client_options)) do |f| | |
66 | - f.use Searchkick::Middleware | |
67 | - f.request signer_middleware_key, signer_middleware_aws_params if aws_credentials | |
61 | + client_type = | |
62 | + if ENV["OPENSEARCH_URL"] | |
63 | + :opensearch | |
64 | + elsif ENV["ELASTICSEARCH_URL"] | |
65 | + :elasticsearch | |
66 | + elsif defined?(OpenSearch::Client) | |
67 | + :opensearch | |
68 | + elsif defined?(Elasticsearch::Client) | |
69 | + :elasticsearch | |
70 | + else | |
71 | + raise ClientNotFound, "Install the `opensearch-ruby` or `elasticsearch` gem" | |
72 | + end | |
73 | + | |
74 | + if client_type == :opensearch | |
75 | + OpenSearch::Client.new({ | |
76 | + url: ENV["OPENSEARCH_URL"], | |
77 | + transport_options: {request: {timeout: timeout}, headers: {content_type: "application/json"}}, | |
78 | + retry_on_failure: 2 | |
79 | + }.deep_merge(client_options)) do |f| | |
80 | + f.use Searchkick::Middleware | |
81 | + f.request signer_middleware_key, signer_middleware_aws_params if aws_credentials | |
82 | + end | |
83 | + else | |
84 | + # TODO check version >= 7 | |
85 | + Elasticsearch::Client.new({ | |
86 | + url: ENV["ELASTICSEARCH_URL"], | |
87 | + transport_options: {request: {timeout: timeout}, headers: {content_type: "application/json"}}, | |
88 | + retry_on_failure: 2 | |
89 | + }.deep_merge(client_options)) do |f| | |
90 | + f.use Searchkick::Middleware | |
91 | + f.request signer_middleware_key, signer_middleware_aws_params if aws_credentials | |
92 | + end | |
68 | 93 | end |
69 | 94 | end |
70 | 95 | end | ... | ... |
lib/searchkick/middleware.rb
searchkick.gemspec