Commit 1e07f15658dc1e1e8a5ba3e2ab6782c143b28ff1
1 parent
ba7dc089
Exists in
master
and in
2 other branches
Less magic for client selection [skip ci]
Showing
1 changed file
with
6 additions
and
7 deletions
Show diff stats
lib/searchkick.rb
... | ... | @@ -56,10 +56,9 @@ module Searchkick |
56 | 56 | class InvalidQueryError < Error; end |
57 | 57 | class DangerousOperation < Error; end |
58 | 58 | class ImportError < Error; end |
59 | - class ClientNotFound < Error; end | |
60 | 59 | |
61 | 60 | class << self |
62 | - attr_accessor :search_method_name, :timeout, :models, :client_options, :redis, :index_prefix, :index_suffix, :queue_name, :model_options | |
61 | + attr_accessor :search_method_name, :timeout, :models, :client_options, :redis, :index_prefix, :index_suffix, :queue_name, :model_options, :client_type | |
63 | 62 | attr_writer :client, :env, :search_timeout |
64 | 63 | attr_reader :aws_credentials |
65 | 64 | end |
... | ... | @@ -73,16 +72,16 @@ module Searchkick |
73 | 72 | def self.client |
74 | 73 | @client ||= begin |
75 | 74 | client_type = |
76 | - if ENV["OPENSEARCH_URL"] | |
77 | - :opensearch | |
78 | - elsif ENV["ELASTICSEARCH_URL"] | |
79 | - :elasticsearch | |
75 | + if self.client_type | |
76 | + self.client_type | |
77 | + elsif defined?(OpenSearch::Client) && defined?(Elasticsearch::Client) | |
78 | + raise Error, "Multiple clients found - set Searchkick.client_type = :elasticsearch or :opensearch" | |
80 | 79 | elsif defined?(OpenSearch::Client) |
81 | 80 | :opensearch |
82 | 81 | elsif defined?(Elasticsearch::Client) |
83 | 82 | :elasticsearch |
84 | 83 | else |
85 | - raise ClientNotFound, "Install the `opensearch-ruby` or `elasticsearch` gem" | |
84 | + raise Error, "No client found - install the `elasticsearch` or `opensearch-ruby` gem" | |
86 | 85 | end |
87 | 86 | |
88 | 87 | # check after client to ensure faraday is installed | ... | ... |