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 +6,7 @@ | ||
6 | - Raise `ArgumentError` instead of `RuntimeError` for unknown operators | 6 | - Raise `ArgumentError` instead of `RuntimeError` for unknown operators |
7 | - Removed mapping of `id` to `_id` with `order` option | 7 | - Removed mapping of `id` to `_id` with `order` option |
8 | - Removed `wordnet` option | 8 | - Removed `wordnet` option |
9 | +- Removed `elasticsearch` dependency | ||
9 | - Dropped support for Ruby < 2.6 and Active Record < 5.2 | 10 | - Dropped support for Ruby < 2.6 and Active Record < 5.2 |
10 | - Dropped support for NoBrainer and Cequel | 11 | - Dropped support for NoBrainer and Cequel |
11 | - Dropped support for `faraday_middleware-aws-signers-v4` (use `faraday_middleware-aws-sigv4` instead) | 12 | - Dropped support for `faraday_middleware-aws-signers-v4` (use `faraday_middleware-aws-sigv4` instead) |
Gemfile
@@ -7,6 +7,7 @@ gem "minitest", ">= 5" | @@ -7,6 +7,7 @@ gem "minitest", ">= 5" | ||
7 | gem "activerecord", "~> 7.0.0" | 7 | gem "activerecord", "~> 7.0.0" |
8 | gem "activejob", "~> 7.0.0", require: "active_job" | 8 | gem "activejob", "~> 7.0.0", require: "active_job" |
9 | gem "actionpack", "~> 7.0.0" | 9 | gem "actionpack", "~> 7.0.0" |
10 | +gem "elasticsearch" | ||
10 | gem "sqlite3" | 11 | gem "sqlite3" |
11 | gem "gemoji-parser" | 12 | gem "gemoji-parser" |
12 | gem "typhoeus" | 13 | gem "typhoeus" |
gemfiles/opensearch.gemfile
@@ -13,5 +13,5 @@ gem "typhoeus" | @@ -13,5 +13,5 @@ gem "typhoeus" | ||
13 | gem "redis" | 13 | gem "redis" |
14 | gem "connection_pool" | 14 | gem "connection_pool" |
15 | gem "kaminari" | 15 | gem "kaminari" |
16 | -gem "opensearch-ruby", github: "opensearch-project/opensearch-ruby" | 16 | +gem "opensearch-ruby" |
17 | gem "parallel_tests" | 17 | gem "parallel_tests" |
lib/searchkick.rb
1 | # dependencies | 1 | # dependencies |
2 | require "active_support" | 2 | require "active_support" |
3 | require "active_support/core_ext/hash/deep_merge" | 3 | require "active_support/core_ext/hash/deep_merge" |
4 | -require "elasticsearch" | ||
5 | require "hashie" | 4 | require "hashie" |
6 | 5 | ||
7 | # modules | 6 | # modules |
@@ -41,6 +40,7 @@ module Searchkick | @@ -41,6 +40,7 @@ module Searchkick | ||
41 | class InvalidQueryError < Error; end | 40 | class InvalidQueryError < Error; end |
42 | class DangerousOperation < Error; end | 41 | class DangerousOperation < Error; end |
43 | class ImportError < Error; end | 42 | class ImportError < Error; end |
43 | + class ClientNotFound < Error; end | ||
44 | 44 | ||
45 | class << self | 45 | class << self |
46 | attr_accessor :search_method_name, :timeout, :models, :client_options, :redis, :index_prefix, :index_suffix, :queue_name, :model_options | 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,13 +58,38 @@ module Searchkick | ||
58 | @client ||= begin | 58 | @client ||= begin |
59 | require "typhoeus/adapters/faraday" if defined?(Typhoeus) && Gem::Version.new(Faraday::VERSION) < Gem::Version.new("0.14.0") | 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 | end | 93 | end |
69 | end | 94 | end |
70 | end | 95 | end |
lib/searchkick/middleware.rb
searchkick.gemspec
@@ -16,6 +16,5 @@ Gem::Specification.new do |spec| | @@ -16,6 +16,5 @@ Gem::Specification.new do |spec| | ||
16 | spec.required_ruby_version = ">= 2.6" | 16 | spec.required_ruby_version = ">= 2.6" |
17 | 17 | ||
18 | spec.add_dependency "activemodel", ">= 5.2" | 18 | spec.add_dependency "activemodel", ">= 5.2" |
19 | - spec.add_dependency "elasticsearch", ">= 6", "< 7.14" | ||
20 | spec.add_dependency "hashie" | 19 | spec.add_dependency "hashie" |
21 | end | 20 | end |