diff --git a/README.md b/README.md index 91bc18c..984d2a8 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,13 @@ Available config options are: * `auto_refresh` tells SearchFlip to automatically refresh an index after import, index, delete, etc operations. This is e.g. useful for testing, etc. Defaults to false. +* `version` Enforce a specific Elasticsearch version and distribution no matter + which Elasticsearch version is actually installed. Can also be used to prevent + sending requests to determine the version: + +```ruby +SearchFlip::Config[:version] = { number: "2.13", distribution: "opensearch" } +``` ## Usage diff --git a/lib/search_flip/connection.rb b/lib/search_flip/connection.rb index d7eb425..1fc60db 100644 --- a/lib/search_flip/connection.rb +++ b/lib/search_flip/connection.rb @@ -26,7 +26,7 @@ def initialize(options = {}) # @return [String] The Elasticsearch distribution def distribution - @distribution ||= SearchFlip::JSON.parse(version_response.to_s)["version"]["distribution"] + @distribution ||= SearchFlip::Config.dig(:version, :distribution) || SearchFlip::JSON.parse(version_response.to_s)["version"]["distribution"] end # Queries and returns the Elasticsearch version used. @@ -37,7 +37,7 @@ def distribution # @return [String] The Elasticsearch version def version - @version ||= SearchFlip::JSON.parse(version_response.to_s)["version"]["number"] + @version ||= SearchFlip::Config.dig(:version, :number) || SearchFlip::JSON.parse(version_response.to_s)["version"]["number"] end # Queries and returns the Elasticsearch cluster health. diff --git a/lib/search_flip/version.rb b/lib/search_flip/version.rb index c0a0423..1540232 100644 --- a/lib/search_flip/version.rb +++ b/lib/search_flip/version.rb @@ -1,3 +1,3 @@ module SearchFlip - VERSION = "3.8.0" + VERSION = "3.9.0" end diff --git a/spec/search_flip/connection_spec.rb b/spec/search_flip/connection_spec.rb index b566ad2..ad45b2b 100644 --- a/spec/search_flip/connection_spec.rb +++ b/spec/search_flip/connection_spec.rb @@ -5,12 +5,28 @@ it "reutrns the distribution" do expect([nil, "opensearch"]).to include(SearchFlip::Connection.new.distribution) end + + it "returns the distribution from the config when given" do + SearchFlip::Config[:version] = { distribution: "distribution" } + + expect(SearchFlip::Connection.new.distribution).to eq("distribution") + ensure + SearchFlip::Config.delete(:version) + end end describe "#version" do it "returns the version" do expect(SearchFlip::Connection.new.version).to match(/\A[0-9.]+\z/) end + + it "returns the version from the config when given" do + SearchFlip::Config[:version] = { number: "1.2.3" } + + expect(SearchFlip::Connection.new.version).to eq("1.2.3") + ensure + SearchFlip::Config.delete(:version) + end end describe "#cluster_health" do