search_flip 4.0.0.beta3 → 4.0.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +2 -1
- data/.rubocop.yml +2 -1
- data/CHANGELOG.md +4 -0
- data/README.md +0 -47
- data/lib/search_flip/bulk.rb +1 -1
- data/lib/search_flip/connection.rb +30 -15
- data/lib/search_flip/index.rb +3 -1
- data/lib/search_flip/json.rb +13 -3
- data/lib/search_flip/to_json.rb +1 -29
- data/lib/search_flip/version.rb +1 -1
- data/spec/search_flip/json_spec.rb +16 -2
- metadata +2 -4
- data/spec/search_flip/to_json_spec.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26839c09be4ddaecd0107d683afc1c16516c0ef562b3e9cb8652b6e0c1818003
|
4
|
+
data.tar.gz: 22e8e36e94439280e8cb0caca5ccd0f3f552ec7518bdffaeb43365e5c8cbbea3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 001b1042dd9f7f2d103adc48789c658e12c6a5abb4e223c72d0d405a41159d37cbe2d3a2a4c76efe125befed963470c518e806b31223ca468f700f3b06e6674b
|
7
|
+
data.tar.gz: d410d8a68b66496c246dac4b573c463b5fe08c4a998bff84146c6665a622a72ff524384d4ffb80d76ef83464858268816c794ab966ae1bba9ed962dd2ed7a105
|
data/.github/workflows/test.yml
CHANGED
@@ -11,7 +11,7 @@ jobs:
|
|
11
11
|
- elasticsearch:5.4
|
12
12
|
- docker.elastic.co/elasticsearch/elasticsearch:6.7.0
|
13
13
|
- docker.elastic.co/elasticsearch/elasticsearch:7.0.0
|
14
|
-
- docker.elastic.co/elasticsearch/elasticsearch:7.
|
14
|
+
- docker.elastic.co/elasticsearch/elasticsearch:7.11.2
|
15
15
|
ruby:
|
16
16
|
- 2.5
|
17
17
|
- 2.6
|
@@ -28,6 +28,7 @@ jobs:
|
|
28
28
|
- uses: actions/setup-ruby@v1
|
29
29
|
with:
|
30
30
|
ruby-version: ${{ matrix.ruby }}
|
31
|
+
- run: gem install bundler
|
31
32
|
- run: bundle
|
32
33
|
- run: sleep 10
|
33
34
|
- run: bundle exec rspec
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -11,6 +11,10 @@
|
|
11
11
|
* Added `SearchFlip::Connection#get_cluster_settings` and
|
12
12
|
`#update_cluster_settings`
|
13
13
|
|
14
|
+
## v3.2.1
|
15
|
+
|
16
|
+
* Fix `refresh` having a empty body breaking in elasticsearch 7.11
|
17
|
+
|
14
18
|
## v3.2.0
|
15
19
|
|
16
20
|
* Fix `index_scope` not being passed in `each_record` without block
|
data/README.md
CHANGED
@@ -882,53 +882,6 @@ Thus, if your ORM supports `.find_each`, `#id` and `#where` you are already
|
|
882
882
|
good to go. Otherwise, simply add your custom implementation of those methods
|
883
883
|
that work with whatever ORM you use.
|
884
884
|
|
885
|
-
## Date and Timestamps in JSON
|
886
|
-
|
887
|
-
Elasticsearch requires dates and timestamps to have one of the formats listed
|
888
|
-
here: [https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html#strict-date-time](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html#strict-date-time).
|
889
|
-
|
890
|
-
However, `JSON.generate` in ruby by default outputs something like:
|
891
|
-
|
892
|
-
```ruby
|
893
|
-
JSON.generate(time: Time.now.utc)
|
894
|
-
# => "{\"time\":\"2018-02-22 18:19:33 UTC\"}"
|
895
|
-
```
|
896
|
-
|
897
|
-
This format is not compatible with Elasticsearch by default. If you're on
|
898
|
-
Rails, ActiveSupport adds its own `#to_json` methods to `Time`, `Date`, etc.
|
899
|
-
However, ActiveSupport checks whether they are used in combination with
|
900
|
-
`JSON.generate` or not and adapt:
|
901
|
-
|
902
|
-
```ruby
|
903
|
-
Time.now.utc.to_json
|
904
|
-
=> "\"2018-02-22T18:18:22.088Z\""
|
905
|
-
|
906
|
-
JSON.generate(time: Time.now.utc)
|
907
|
-
=> "{\"time\":\"2018-02-22 18:18:59 UTC\"}"
|
908
|
-
```
|
909
|
-
|
910
|
-
SearchFlip is using the [Oj gem](https://github.com/ohler55/oj) to generate
|
911
|
-
JSON. More concretely, SearchFlip is using:
|
912
|
-
|
913
|
-
```ruby
|
914
|
-
Oj.dump({ key: "value" }, mode: :custom, use_to_json: true)
|
915
|
-
```
|
916
|
-
|
917
|
-
This mitigates the issues if you're on Rails:
|
918
|
-
|
919
|
-
```ruby
|
920
|
-
Oj.dump(Time.now, mode: :custom, use_to_json: true)
|
921
|
-
# => "\"2018-02-22T18:21:21.064Z\""
|
922
|
-
```
|
923
|
-
|
924
|
-
However, if you're not on Rails, you need to add `#to_json` methods to `Time`,
|
925
|
-
`Date` and `DateTime` to get proper serialization. You can either add them on
|
926
|
-
your own, via other libraries or by simply using:
|
927
|
-
|
928
|
-
```ruby
|
929
|
-
require "search_flip/to_json"
|
930
|
-
```
|
931
|
-
|
932
885
|
## Feature Support
|
933
886
|
|
934
887
|
* for Elasticsearch 2.x, the delete-by-query plugin is required to delete
|
data/lib/search_flip/bulk.rb
CHANGED
@@ -28,7 +28,9 @@ module SearchFlip
|
|
28
28
|
# @return [Hash] The cluster settings
|
29
29
|
|
30
30
|
def get_cluster_settings
|
31
|
-
http_client.get("#{base_url}/_cluster/settings")
|
31
|
+
response = http_client.get("#{base_url}/_cluster/settings")
|
32
|
+
|
33
|
+
SearchFlip::JSON.parse(response.to_s)
|
32
34
|
end
|
33
35
|
|
34
36
|
# Updates the cluster settings according to the specified payload
|
@@ -55,7 +57,11 @@ module SearchFlip
|
|
55
57
|
|
56
58
|
def version
|
57
59
|
@version_mutex.synchronize do
|
58
|
-
@version ||=
|
60
|
+
@version ||= begin
|
61
|
+
response = http_client.headers(accept: "application/json").get("#{base_url}/")
|
62
|
+
|
63
|
+
SearchFlip::JSON.parse(response.to_s)["version"]["number"]
|
64
|
+
end
|
59
65
|
end
|
60
66
|
end
|
61
67
|
|
@@ -67,7 +73,9 @@ module SearchFlip
|
|
67
73
|
# @return [Hash] The raw response
|
68
74
|
|
69
75
|
def cluster_health
|
70
|
-
http_client.headers(accept: "application/json").get("#{base_url}/_cluster/health")
|
76
|
+
response = http_client.headers(accept: "application/json").get("#{base_url}/_cluster/health")
|
77
|
+
|
78
|
+
SearchFlip::JSON.parse(response.to_s)
|
71
79
|
end
|
72
80
|
|
73
81
|
# Uses the Elasticsearch Multi Search API to execute multiple search requests
|
@@ -117,10 +125,11 @@ module SearchFlip
|
|
117
125
|
# @return [Hash] The raw response
|
118
126
|
|
119
127
|
def update_aliases(payload)
|
120
|
-
http_client
|
128
|
+
response = http_client
|
121
129
|
.headers(accept: "application/json", content_type: "application/json")
|
122
130
|
.post("#{base_url}/_aliases", body: SearchFlip::JSON.generate(payload))
|
123
|
-
|
131
|
+
|
132
|
+
SearchFlip::JSON.parse(response.to_s)
|
124
133
|
end
|
125
134
|
|
126
135
|
# Sends an analyze request to Elasticsearch. Raises
|
@@ -132,10 +141,11 @@ module SearchFlip
|
|
132
141
|
# @return [Hash] The raw response
|
133
142
|
|
134
143
|
def analyze(request, params = {})
|
135
|
-
http_client
|
144
|
+
response = http_client
|
136
145
|
.headers(accept: "application/json")
|
137
146
|
.post("#{base_url}/_analyze", json: request, params: params)
|
138
|
-
|
147
|
+
|
148
|
+
SearchFlip::JSON.parse(response.to_s)
|
139
149
|
end
|
140
150
|
|
141
151
|
# Fetches information about the specified index aliases. Raises
|
@@ -151,10 +161,11 @@ module SearchFlip
|
|
151
161
|
# @return [Hash] The raw response
|
152
162
|
|
153
163
|
def get_aliases(index_name: "*", alias_name: "*")
|
154
|
-
http_client
|
164
|
+
response = http_client
|
155
165
|
.headers(accept: "application/json", content_type: "application/json")
|
156
166
|
.get("#{base_url}/#{index_name}/_alias/#{alias_name}")
|
157
|
-
|
167
|
+
|
168
|
+
SearchFlip::JSON.parse(response.to_s)
|
158
169
|
end
|
159
170
|
|
160
171
|
# Returns whether or not the associated Elasticsearch alias already
|
@@ -186,10 +197,11 @@ module SearchFlip
|
|
186
197
|
# @return [Array] The raw response
|
187
198
|
|
188
199
|
def get_indices(name = "*", params: {})
|
189
|
-
http_client
|
200
|
+
response = http_client
|
190
201
|
.headers(accept: "application/json", content_type: "application/json")
|
191
202
|
.get("#{base_url}/_cat/indices/#{name}", params: params)
|
192
|
-
|
203
|
+
|
204
|
+
SearchFlip::JSON.parse(response.to_s)
|
193
205
|
end
|
194
206
|
|
195
207
|
alias_method :cat_indices, :get_indices
|
@@ -286,10 +298,11 @@ module SearchFlip
|
|
286
298
|
# @return [Hash] The index settings
|
287
299
|
|
288
300
|
def get_index_settings(index_name)
|
289
|
-
http_client
|
301
|
+
response = http_client
|
290
302
|
.headers(accept: "application/json")
|
291
303
|
.get("#{index_url(index_name)}/_settings")
|
292
|
-
|
304
|
+
|
305
|
+
SearchFlip::JSON.parse(response.to_s)
|
293
306
|
end
|
294
307
|
|
295
308
|
# Sends a refresh request to Elasticsearch. Raises
|
@@ -299,7 +312,7 @@ module SearchFlip
|
|
299
312
|
# @return [Boolean] Returns true or raises SearchFlip::ResponseError
|
300
313
|
|
301
314
|
def refresh(index_names = nil)
|
302
|
-
http_client.post("#{index_names ? index_url(Array(index_names).join(",")) : base_url}/_refresh"
|
315
|
+
http_client.post("#{index_names ? index_url(Array(index_names).join(",")) : base_url}/_refresh")
|
303
316
|
|
304
317
|
true
|
305
318
|
end
|
@@ -337,7 +350,9 @@ module SearchFlip
|
|
337
350
|
url = type_name ? type_url(index_name, type_name) : index_url(index_name)
|
338
351
|
params = type_name && version.to_f >= 6.7 ? { include_type_name: true } : {}
|
339
352
|
|
340
|
-
http_client.headers(accept: "application/json").get("#{url}/_mapping", params: params)
|
353
|
+
response = http_client.headers(accept: "application/json").get("#{url}/_mapping", params: params)
|
354
|
+
|
355
|
+
SearchFlip::JSON.parse(response.to_s)
|
341
356
|
end
|
342
357
|
|
343
358
|
# Deletes the specified index from Elasticsearch. Raises
|
data/lib/search_flip/index.rb
CHANGED
@@ -487,7 +487,9 @@ module SearchFlip
|
|
487
487
|
# @return [Hash] The raw response
|
488
488
|
|
489
489
|
def analyze(request, params = {})
|
490
|
-
connection.http_client.headers(accept: "application/json").post("#{index_url}/_analyze", json: request, params: params)
|
490
|
+
response = connection.http_client.headers(accept: "application/json").post("#{index_url}/_analyze", json: request, params: params)
|
491
|
+
|
492
|
+
SearchFlip::JSON.parse(response.to_s)
|
491
493
|
end
|
492
494
|
|
493
495
|
# Sends a index refresh request to Elasticsearch. Raises
|
data/lib/search_flip/json.rb
CHANGED
@@ -1,11 +1,21 @@
|
|
1
1
|
module SearchFlip
|
2
2
|
class JSON
|
3
|
+
@default_options = {
|
4
|
+
mode: :custom,
|
5
|
+
time_format: :xmlschema,
|
6
|
+
bigdecimal_as_decimal: false
|
7
|
+
}
|
8
|
+
|
9
|
+
def self.default_options
|
10
|
+
@default_options
|
11
|
+
end
|
12
|
+
|
3
13
|
def self.generate(obj)
|
4
|
-
Oj.dump(obj,
|
14
|
+
Oj.dump(obj, default_options)
|
5
15
|
end
|
6
16
|
|
7
|
-
def self.parse(
|
8
|
-
Oj.load(
|
17
|
+
def self.parse(json)
|
18
|
+
Oj.load(json, default_options)
|
9
19
|
end
|
10
20
|
end
|
11
21
|
end
|
data/lib/search_flip/to_json.rb
CHANGED
@@ -1,29 +1 @@
|
|
1
|
-
|
2
|
-
require "date"
|
3
|
-
require "json"
|
4
|
-
|
5
|
-
class Time
|
6
|
-
def to_json(*args)
|
7
|
-
iso8601(6).to_json
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
class Date
|
12
|
-
def to_json(*args)
|
13
|
-
iso8601.to_json
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class DateTime
|
18
|
-
def to_json(*args)
|
19
|
-
iso8601(6).to_json
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
if defined?(ActiveSupport)
|
24
|
-
class ActiveSupport::TimeWithZone
|
25
|
-
def to_json(*args)
|
26
|
-
iso8601(6).to_json
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
1
|
+
warn "[DEPRECATION] Using search_flip/to_json is not neccessary anymore"
|
data/lib/search_flip/version.rb
CHANGED
@@ -2,6 +2,16 @@ require File.expand_path("../spec_helper", __dir__)
|
|
2
2
|
|
3
3
|
RSpec.describe SearchFlip::JSON do
|
4
4
|
describe ".generate" do
|
5
|
+
it "encodes timestamps correctly" do
|
6
|
+
Timecop.freeze "2020-06-01 12:00:00 UTC" do
|
7
|
+
expect(described_class.generate(timestamp: Time.now.utc)).to eq('{"timestamp":"2020-06-01T12:00:00Z"}')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "encodes bigdecimals as string" do
|
12
|
+
expect(described_class.generate(value: BigDecimal(1))).to eq('{"value":"1.0"}')
|
13
|
+
end
|
14
|
+
|
5
15
|
it "delegates to Oj" do
|
6
16
|
allow(Oj).to receive(:dump)
|
7
17
|
|
@@ -9,7 +19,7 @@ RSpec.describe SearchFlip::JSON do
|
|
9
19
|
|
10
20
|
described_class.generate(payload)
|
11
21
|
|
12
|
-
expect(Oj).to have_received(:dump).with(payload, mode: :custom,
|
22
|
+
expect(Oj).to have_received(:dump).with(payload, mode: :custom, time_format: :xmlschema, bigdecimal_as_decimal: false)
|
13
23
|
end
|
14
24
|
|
15
25
|
it "generates json" do
|
@@ -18,6 +28,10 @@ RSpec.describe SearchFlip::JSON do
|
|
18
28
|
end
|
19
29
|
|
20
30
|
describe ".parse" do
|
31
|
+
it "returns the parsed json payload" do
|
32
|
+
expect(described_class.parse('{"key":"value"}')).to eq("key" => "value")
|
33
|
+
end
|
34
|
+
|
21
35
|
it "delegates to Oj" do
|
22
36
|
allow(Oj).to receive(:load)
|
23
37
|
|
@@ -25,7 +39,7 @@ RSpec.describe SearchFlip::JSON do
|
|
25
39
|
|
26
40
|
described_class.parse(payload)
|
27
41
|
|
28
|
-
expect(Oj).to have_received(:load).with(payload, mode: :
|
42
|
+
expect(Oj).to have_received(:load).with(payload, mode: :custom, time_format: :xmlschema, bigdecimal_as_decimal: false)
|
29
43
|
end
|
30
44
|
end
|
31
45
|
end
|
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.beta4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Vetter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -250,7 +250,6 @@ files:
|
|
250
250
|
- spec/search_flip/null_instrumenter_spec.rb
|
251
251
|
- spec/search_flip/response_spec.rb
|
252
252
|
- spec/search_flip/result_spec.rb
|
253
|
-
- spec/search_flip/to_json_spec.rb
|
254
253
|
- spec/spec_helper.rb
|
255
254
|
homepage: https://github.com/mrkamel/search_flip
|
256
255
|
licenses:
|
@@ -292,5 +291,4 @@ test_files:
|
|
292
291
|
- spec/search_flip/null_instrumenter_spec.rb
|
293
292
|
- spec/search_flip/response_spec.rb
|
294
293
|
- spec/search_flip/result_spec.rb
|
295
|
-
- spec/search_flip/to_json_spec.rb
|
296
294
|
- spec/spec_helper.rb
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require File.expand_path("../spec_helper", __dir__)
|
2
|
-
require "search_flip/to_json"
|
3
|
-
|
4
|
-
RSpec.describe "to_json" do
|
5
|
-
it "uses the correct format for Time" do
|
6
|
-
Timecop.freeze Time.parse("2018-01-01 12:00:00 UTC") do
|
7
|
-
expect(Time.now.utc.to_json).to eq("\"2018-01-01T12:00:00.000000Z\"")
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
it "uses the correct format for Date" do
|
12
|
-
Timecop.freeze Time.parse("2018-01-01 12:00:00 UTC") do
|
13
|
-
expect(Date.today.to_json).to eq("\"2018-01-01\"")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it "uses the correct format for DateTime" do
|
18
|
-
Timecop.freeze Time.parse("2018-01-01 12:00:00 UTC") do
|
19
|
-
expect(Time.now.utc.to_json).to eq("\"2018-01-01T12:00:00.000000Z\"")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it "uses the correct format for TimeWithZone" do
|
24
|
-
Timecop.freeze Time.parse("2018-01-01 12:00:00 UTC") do
|
25
|
-
expect(Time.find_zone("UTC").now.to_json).to eq("\"2018-01-01T12:00:00.000000Z\"")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|