diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9335e89..ed4dd85 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,6 +39,10 @@ jobs: env: discovery.type: single-node plugins.security.disabled: true + - image: opensearchproject/opensearch:2.13.0 + env: + discovery.type: single-node + DISABLE_SECURITY_PLUGIN: true ruby: - 2.7 - 3.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index bfb7260..58584e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,20 @@ * Added `SearchFlip::Connection#get_cluster_settings` and `#update_cluster_settings` -## v3.8.0. +## v3.9.0 + +* Allow to configure the elasticsearch version no matter which elasticsearch + version is actually in use. The version information is needed to support + version dependent features. Please note that manually configuring the version + is usually not need as the version by default is determined by sending one + request to elasticsearch. + +```ruby +SearchFlip::Config[:version] = { number: "8.1.1" } +SearchFlip::Config[:version] = { number: "2.13", distribution: "opensearch" } +``` + +## v3.8.0 * Support Opensearch 1.x and 2.x diff --git a/Gemfile b/Gemfile index b1c1c0f..6fafb84 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,6 @@ gem "factory_bot" gem "rake" gem "rspec" gem "rubocop" -gem "sqlite3" +gem "sqlite3", "~> 1.4" gem "timecop" gem "webmock" diff --git a/README.md b/README.md index f9dc41e..ad23d57 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,16 @@ 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` allows to configure the elasticsearch version no matter which + elasticsearch version is actually in use. The version information is needed to + support version dependent features. Please note that manually configuring the + version is usually not need as the version by default is determined by sending + one request to elasticsearch. + +```ruby +SearchFlip::Config[:version] = { number: "8.1.1" } +SearchFlip::Config[:version] = { number: "2.13", distribution: "opensearch" } +``` ## Usage diff --git a/lib/search_flip/connection.rb b/lib/search_flip/connection.rb index abeeeb0..415e7ef 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 the cluster settings from Elasticsearch @@ -66,7 +66,7 @@ def update_cluster_settings(cluster_settings) # @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 96dfc3c..42931ba 100644 --- a/lib/search_flip/version.rb +++ b/lib/search_flip/version.rb @@ -1,3 +1,3 @@ module SearchFlip - VERSION = "4.0.0.beta14" + VERSION = "4.0.0.beta16" end diff --git a/spec/search_flip/connection_spec.rb b/spec/search_flip/connection_spec.rb index 7a62e26..5136e83 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