search_flip 4.0.0.beta14 → 4.0.0.beta15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +4 -0
- data/CHANGELOG.md +14 -1
- data/Gemfile +1 -1
- data/README.md +10 -0
- data/lib/search_flip/connection.rb +2 -2
- data/lib/search_flip/json.rb +1 -1
- data/lib/search_flip/response.rb +3 -3
- data/lib/search_flip/result.rb +2 -28
- data/lib/search_flip/version.rb +1 -1
- data/spec/search_flip/connection_spec.rb +16 -0
- data/spec/search_flip/json_spec.rb +1 -1
- data/spec/search_flip/result_spec.rb +3 -12
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cbf6d1f0c653af6bc398768eff11d7715c1cea101a06f4eefb1c6078ad33abc1
|
|
4
|
+
data.tar.gz: c2568175d32374201ea212abfdebd709d8933c92c19cc646225b7bd90244498c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3f28cc23ad081e6345764799b2f70b957c9be97fab7781f22fbee580ed2c28b8da0bb0b3a9c4ef5d4ec200c94a6799a5c082489d9a62b2e24f94c49e29bcd4d1
|
|
7
|
+
data.tar.gz: 1f773fcf838215595db93760a66359acf77a19f63758447a9f30498be90dcce079a2ba21e2ce3350f2b6295e3906b3bb3ea3b5472f0804965b6003e61d94460d
|
data/.github/workflows/test.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -11,7 +11,20 @@
|
|
|
11
11
|
* Added `SearchFlip::Connection#get_cluster_settings` and
|
|
12
12
|
`#update_cluster_settings`
|
|
13
13
|
|
|
14
|
-
## v3.
|
|
14
|
+
## v3.9.0
|
|
15
|
+
|
|
16
|
+
* Allow to configure the elasticsearch version no matter which elasticsearch
|
|
17
|
+
version is actually in use. The version information is needed to support
|
|
18
|
+
version dependent features. Please note that manually configuring the version
|
|
19
|
+
is usually not need as the version by default is determined by sending one
|
|
20
|
+
request to elasticsearch.
|
|
21
|
+
|
|
22
|
+
```ruby
|
|
23
|
+
SearchFlip::Config[:version] = { number: "8.1.1" }
|
|
24
|
+
SearchFlip::Config[:version] = { number: "2.13", distribution: "opensearch" }
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## v3.8.0
|
|
15
28
|
|
|
16
29
|
* Support Opensearch 1.x and 2.x
|
|
17
30
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -98,6 +98,16 @@ Available config options are:
|
|
|
98
98
|
* `auto_refresh` tells SearchFlip to automatically refresh an index after
|
|
99
99
|
import, index, delete, etc operations. This is e.g. useful for testing, etc.
|
|
100
100
|
Defaults to false.
|
|
101
|
+
* `version` allows to configure the elasticsearch version no matter which
|
|
102
|
+
elasticsearch version is actually in use. The version information is needed to
|
|
103
|
+
support version dependent features. Please note that manually configuring the
|
|
104
|
+
version is usually not need as the version by default is determined by sending
|
|
105
|
+
one request to elasticsearch.
|
|
106
|
+
|
|
107
|
+
```ruby
|
|
108
|
+
SearchFlip::Config[:version] = { number: "8.1.1" }
|
|
109
|
+
SearchFlip::Config[:version] = { number: "2.13", distribution: "opensearch" }
|
|
110
|
+
```
|
|
101
111
|
|
|
102
112
|
## Usage
|
|
103
113
|
|
|
@@ -26,7 +26,7 @@ module SearchFlip
|
|
|
26
26
|
# @return [String] The Elasticsearch distribution
|
|
27
27
|
|
|
28
28
|
def distribution
|
|
29
|
-
@distribution ||= SearchFlip::JSON.parse(version_response.to_s)["version"]["distribution"]
|
|
29
|
+
@distribution ||= SearchFlip::Config.dig(:version, :distribution) || SearchFlip::JSON.parse(version_response.to_s)["version"]["distribution"]
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
# Queries the cluster settings from Elasticsearch
|
|
@@ -66,7 +66,7 @@ module SearchFlip
|
|
|
66
66
|
# @return [String] The Elasticsearch version
|
|
67
67
|
|
|
68
68
|
def version
|
|
69
|
-
@version ||= SearchFlip::JSON.parse(version_response.to_s)["version"]["number"]
|
|
69
|
+
@version ||= SearchFlip::Config.dig(:version, :number) || SearchFlip::JSON.parse(version_response.to_s)["version"]["number"]
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
# Queries and returns the Elasticsearch cluster health.
|
data/lib/search_flip/json.rb
CHANGED
data/lib/search_flip/response.rb
CHANGED
|
@@ -305,11 +305,11 @@ module SearchFlip
|
|
|
305
305
|
if response["aggregations"].nil? || response["aggregations"][key].nil?
|
|
306
306
|
SearchFlip::Result.new
|
|
307
307
|
elsif response["aggregations"][key]["buckets"].is_a?(Array)
|
|
308
|
-
response["aggregations"][key]["buckets"].each_with_object({}) { |bucket, hash| hash[bucket["key"]] =
|
|
308
|
+
response["aggregations"][key]["buckets"].each_with_object({}) { |bucket, hash| hash[bucket["key"]] = bucket }
|
|
309
309
|
elsif response["aggregations"][key]["buckets"].is_a?(Hash)
|
|
310
|
-
|
|
310
|
+
response["aggregations"][key]["buckets"]
|
|
311
311
|
else
|
|
312
|
-
|
|
312
|
+
response["aggregations"][key]
|
|
313
313
|
end
|
|
314
314
|
end
|
|
315
315
|
end
|
data/lib/search_flip/result.rb
CHANGED
|
@@ -8,32 +8,6 @@ module SearchFlip
|
|
|
8
8
|
# result.some_key # => "value"
|
|
9
9
|
|
|
10
10
|
class Result < Hash
|
|
11
|
-
def self.convert(hash)
|
|
12
|
-
res = self[hash]
|
|
13
|
-
|
|
14
|
-
res.each do |key, value|
|
|
15
|
-
if value.is_a?(Hash)
|
|
16
|
-
res[key] = convert(value)
|
|
17
|
-
elsif value.is_a?(Array)
|
|
18
|
-
res[key] = convert_array(value)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
res
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def self.convert_array(arr)
|
|
26
|
-
arr.map do |obj|
|
|
27
|
-
if obj.is_a?(Hash)
|
|
28
|
-
convert(obj)
|
|
29
|
-
elsif obj.is_a?(Array)
|
|
30
|
-
convert_array(obj)
|
|
31
|
-
else
|
|
32
|
-
obj
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
11
|
def method_missing(name, *args, &block)
|
|
38
12
|
self[name.to_s]
|
|
39
13
|
end
|
|
@@ -43,8 +17,8 @@ module SearchFlip
|
|
|
43
17
|
end
|
|
44
18
|
|
|
45
19
|
def self.from_hit(hit)
|
|
46
|
-
res =
|
|
47
|
-
res["_hit"] =
|
|
20
|
+
res = self[hit["_source"] || {}]
|
|
21
|
+
res["_hit"] = self[hit].tap { |hash| hash.delete("_source") }
|
|
48
22
|
res
|
|
49
23
|
end
|
|
50
24
|
end
|
data/lib/search_flip/version.rb
CHANGED
|
@@ -5,12 +5,28 @@ RSpec.describe SearchFlip::Connection do
|
|
|
5
5
|
it "reutrns the distribution" do
|
|
6
6
|
expect([nil, "opensearch"]).to include(SearchFlip::Connection.new.distribution)
|
|
7
7
|
end
|
|
8
|
+
|
|
9
|
+
it "returns the distribution from the config when given" do
|
|
10
|
+
SearchFlip::Config[:version] = { distribution: "distribution" }
|
|
11
|
+
|
|
12
|
+
expect(SearchFlip::Connection.new.distribution).to eq("distribution")
|
|
13
|
+
ensure
|
|
14
|
+
SearchFlip::Config.delete(:version)
|
|
15
|
+
end
|
|
8
16
|
end
|
|
9
17
|
|
|
10
18
|
describe "#version" do
|
|
11
19
|
it "returns the version" do
|
|
12
20
|
expect(SearchFlip::Connection.new.version).to match(/\A[0-9.]+\z/)
|
|
13
21
|
end
|
|
22
|
+
|
|
23
|
+
it "returns the version from the config when given" do
|
|
24
|
+
SearchFlip::Config[:version] = { number: "1.2.3" }
|
|
25
|
+
|
|
26
|
+
expect(SearchFlip::Connection.new.version).to eq("1.2.3")
|
|
27
|
+
ensure
|
|
28
|
+
SearchFlip::Config.delete(:version)
|
|
29
|
+
end
|
|
14
30
|
end
|
|
15
31
|
|
|
16
32
|
describe "#cluster_health" do
|
|
@@ -1,26 +1,17 @@
|
|
|
1
1
|
require File.expand_path("../spec_helper", __dir__)
|
|
2
2
|
|
|
3
3
|
RSpec.describe SearchFlip::Result do
|
|
4
|
-
describe ".convert" do
|
|
5
|
-
it "deeply converts hashes and arrays" do
|
|
6
|
-
result = described_class.convert("parent" => { "child" => [{ "key1" => "value" }, { "key2" => 3 }] })
|
|
7
|
-
|
|
8
|
-
expect(result.parent.child[0].key1).to eq("value")
|
|
9
|
-
expect(result.parent.child[1].key2).to eq(3)
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
4
|
describe "#method_missing" do
|
|
14
5
|
it "returns the value of the key equal to the message name" do
|
|
15
|
-
expect(described_class
|
|
6
|
+
expect(described_class["some_key" => "value"].some_key).to eq("value")
|
|
16
7
|
expect(described_class.new.some_key).to be_nil
|
|
17
8
|
end
|
|
18
9
|
end
|
|
19
10
|
|
|
20
11
|
describe "#responds_to_missing?" do
|
|
21
12
|
it "returns true/false if the key equal to the message name is present or not" do
|
|
22
|
-
expect(described_class
|
|
23
|
-
expect(described_class
|
|
13
|
+
expect(described_class["some_key" => nil].respond_to?(:some_key)).to eq(true)
|
|
14
|
+
expect(described_class["some_key" => nil].respond_to?(:other_key)).to eq(false)
|
|
24
15
|
end
|
|
25
16
|
end
|
|
26
17
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: search_flip
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.0.0.
|
|
4
|
+
version: 4.0.0.beta15
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Benjamin Vetter
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-
|
|
11
|
+
date: 2024-07-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: http
|