Skip to content

Commit

Permalink
Allow to configure the elasticsearch version (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkamel authored Jul 8, 2024
1 parent 9396f91 commit 4705bd3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@

# CHANGELOG

## 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

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/search_flip/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/search_flip/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SearchFlip
VERSION = "3.8.0"
VERSION = "3.9.0"
end
16 changes: 16 additions & 0 deletions spec/search_flip/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4705bd3

Please sign in to comment.