search_flip 3.5.0 → 3.6.0
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 +2 -1
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +4 -0
- data/docker-compose.yml +1 -0
- data/lib/search_flip/connection.rb +5 -5
- data/lib/search_flip/criteria.rb +9 -3
- data/lib/search_flip/index.rb +7 -3
- data/lib/search_flip/version.rb +1 -1
- data/spec/search_flip/aws_sigv4_plugin_spec.rb +6 -4
- data/spec/search_flip/bulk_spec.rb +5 -8
- data/spec/search_flip/connection_spec.rb +12 -5
- data/spec/search_flip/criteria_spec.rb +15 -3
- data/spec/search_flip/index_spec.rb +11 -3
- data/spec/spec_helper.rb +3 -3
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a241c0ab86244a53caab6b7d8dbcd8f441d9e7fc40837cc9afa7f57e6c7e5da0
|
|
4
|
+
data.tar.gz: f42562bd8af88780accd33c91c112c9f81b42de8945aa956c118b7faff75c6f6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad60516d947d060ca1fe049a80059c18e9deb76f7c380b0279cd11cd5b5e0fb811d3a46a12220fd731b793ce1a6728f23e6cb242410f584d040e874a2bed7d78
|
|
7
|
+
data.tar.gz: 415962179b2e3ead79296851746b5f4892bdfbce64d09ae6ef2a2f0df83fa265b1c00a8a549d42013911eaff7ecc0b0460d20ef5c72d096f070d1adce4d0797c
|
data/.github/workflows/test.yml
CHANGED
|
@@ -12,6 +12,7 @@ jobs:
|
|
|
12
12
|
- docker.elastic.co/elasticsearch/elasticsearch:6.7.0
|
|
13
13
|
- docker.elastic.co/elasticsearch/elasticsearch:7.0.0
|
|
14
14
|
- docker.elastic.co/elasticsearch/elasticsearch:7.11.2
|
|
15
|
+
- docker.elastic.co/elasticsearch/elasticsearch:8.1.1
|
|
15
16
|
ruby:
|
|
16
17
|
- 2.6
|
|
17
18
|
- 2.7
|
|
@@ -21,6 +22,7 @@ jobs:
|
|
|
21
22
|
image: ${{ matrix.elasticsearch }}
|
|
22
23
|
env:
|
|
23
24
|
discovery.type: single-node
|
|
25
|
+
xpack.security.enabled: false
|
|
24
26
|
ports:
|
|
25
27
|
- 9200:9200
|
|
26
28
|
steps:
|
|
@@ -30,6 +32,5 @@ jobs:
|
|
|
30
32
|
ruby-version: ${{ matrix.ruby }}
|
|
31
33
|
- run: gem install bundler
|
|
32
34
|
- run: bundle
|
|
33
|
-
- run: sleep 10
|
|
34
35
|
- run: bundle exec rspec
|
|
35
36
|
- run: bundle exec rubocop
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/docker-compose.yml
CHANGED
|
@@ -64,7 +64,7 @@ module SearchFlip
|
|
|
64
64
|
def msearch(criterias)
|
|
65
65
|
payload = criterias.flat_map do |criteria|
|
|
66
66
|
[
|
|
67
|
-
SearchFlip::JSON.generate(index: criteria.target.index_name_with_prefix, type: criteria.target.type_name),
|
|
67
|
+
SearchFlip::JSON.generate(index: criteria.target.index_name_with_prefix, **(version.to_i < 8 ? { type: criteria.target.type_name } : {})),
|
|
68
68
|
SearchFlip::JSON.generate(criteria.request)
|
|
69
69
|
]
|
|
70
70
|
end
|
|
@@ -300,8 +300,8 @@ module SearchFlip
|
|
|
300
300
|
# @return [Boolean] Returns true or raises SearchFlip::ResponseError
|
|
301
301
|
|
|
302
302
|
def update_mapping(index_name, mapping, type_name: nil)
|
|
303
|
-
url = type_name ? type_url(index_name, type_name) : index_url(index_name)
|
|
304
|
-
params = type_name && version.to_f >= 6.7 ? { include_type_name: true } : {}
|
|
303
|
+
url = type_name && version.to_i < 8 ? type_url(index_name, type_name) : index_url(index_name)
|
|
304
|
+
params = type_name && version.to_f >= 6.7 && version.to_i < 8 ? { include_type_name: true } : {}
|
|
305
305
|
|
|
306
306
|
http_client.put("#{url}/_mapping", params: params, json: mapping)
|
|
307
307
|
|
|
@@ -318,8 +318,8 @@ module SearchFlip
|
|
|
318
318
|
# @return [Hash] The current type mapping
|
|
319
319
|
|
|
320
320
|
def get_mapping(index_name, type_name: nil)
|
|
321
|
-
url = type_name ? type_url(index_name, type_name) : index_url(index_name)
|
|
322
|
-
params = type_name && version.to_f >= 6.7 ? { include_type_name: true } : {}
|
|
321
|
+
url = type_name && version.to_i < 8 ? type_url(index_name, type_name) : index_url(index_name)
|
|
322
|
+
params = type_name && version.to_f >= 6.7 && version.to_i < 8 ? { include_type_name: true } : {}
|
|
323
323
|
|
|
324
324
|
response = http_client.headers(accept: "application/json").get("#{url}/_mapping", params: params)
|
|
325
325
|
|
data/lib/search_flip/criteria.rb
CHANGED
|
@@ -351,7 +351,9 @@ module SearchFlip
|
|
|
351
351
|
http_request = http_request.timeout(http_timeout_value) if http_timeout_value
|
|
352
352
|
|
|
353
353
|
if connection.version.to_i >= 5
|
|
354
|
-
|
|
354
|
+
url = connection.version.to_i < 8 ? target.type_url : target.index_url
|
|
355
|
+
|
|
356
|
+
http_request.post("#{url}/_delete_by_query", params: request_params.merge(params), json: dupped_request)
|
|
355
357
|
else
|
|
356
358
|
http_request.delete("#{target.type_url}/_query", params: request_params.merge(params), json: dupped_request)
|
|
357
359
|
end
|
|
@@ -620,13 +622,17 @@ module SearchFlip
|
|
|
620
622
|
json: { scroll: scroll_args[:timeout], scroll_id: scroll_args[:id] }
|
|
621
623
|
)
|
|
622
624
|
elsif scroll_args
|
|
625
|
+
url = connection.version.to_i < 8 ? target.type_url : target.index_url
|
|
626
|
+
|
|
623
627
|
http_request.post(
|
|
624
|
-
"#{
|
|
628
|
+
"#{url}/_search",
|
|
625
629
|
params: request_params.merge(scroll: scroll_args[:timeout]),
|
|
626
630
|
json: request
|
|
627
631
|
)
|
|
628
632
|
else
|
|
629
|
-
|
|
633
|
+
url = connection.version.to_i < 8 ? target.type_url : target.index_url
|
|
634
|
+
|
|
635
|
+
http_request.post("#{url}/_search", params: request_params, json: request)
|
|
630
636
|
end
|
|
631
637
|
|
|
632
638
|
SearchFlip::Response.new(self, SearchFlip::JSON.parse(http_response.to_s))
|
data/lib/search_flip/index.rb
CHANGED
|
@@ -455,7 +455,8 @@ module SearchFlip
|
|
|
455
455
|
# @return [Hash] The specified document
|
|
456
456
|
|
|
457
457
|
def get(id, params = {})
|
|
458
|
-
|
|
458
|
+
url = connection.version.to_i < 8 ? type_url : "#{index_url}/_doc"
|
|
459
|
+
response = connection.http_client.headers(accept: "application/json").get("#{url}/#{id}", params: params)
|
|
459
460
|
|
|
460
461
|
SearchFlip::JSON.parse(response.to_s)
|
|
461
462
|
end
|
|
@@ -473,7 +474,8 @@ module SearchFlip
|
|
|
473
474
|
# @return [Hash] The raw response
|
|
474
475
|
|
|
475
476
|
def mget(request, params = {})
|
|
476
|
-
|
|
477
|
+
url = connection.version.to_i < 8 ? type_url : index_url
|
|
478
|
+
response = connection.http_client.headers(accept: "application/json").post("#{url}/_mget", json: request, params: params)
|
|
477
479
|
|
|
478
480
|
SearchFlip::JSON.parse(response.to_s)
|
|
479
481
|
end
|
|
@@ -631,7 +633,9 @@ module SearchFlip
|
|
|
631
633
|
bulk_max_mb: connection.bulk_max_mb
|
|
632
634
|
}
|
|
633
635
|
|
|
634
|
-
|
|
636
|
+
url = connection.version.to_i < 8 ? type_url : index_url
|
|
637
|
+
|
|
638
|
+
SearchFlip::Bulk.new("#{url}/_bulk", default_options.merge(options)) do |indexer|
|
|
635
639
|
yield indexer
|
|
636
640
|
end
|
|
637
641
|
|
data/lib/search_flip/version.rb
CHANGED
|
@@ -16,10 +16,12 @@ RSpec.describe SearchFlip::AwsSigv4Plugin do
|
|
|
16
16
|
it "adds the signed headers to the request" do
|
|
17
17
|
Timecop.freeze Time.parse("2020-01-01 12:00:00 UTC") do
|
|
18
18
|
expect(client).to receive(:headers).with(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
an_object_matching(
|
|
20
|
+
"host" => "localhost",
|
|
21
|
+
"authorization" => /.*/,
|
|
22
|
+
"x-amz-content-sha256" => /.*/,
|
|
23
|
+
"x-amz-date" => /20200101T120000Z/
|
|
24
|
+
)
|
|
23
25
|
)
|
|
24
26
|
|
|
25
27
|
plugin.call(client, :get, "http://localhost/index")
|
|
@@ -60,18 +60,15 @@ RSpec.describe SearchFlip::Bulk do
|
|
|
60
60
|
|
|
61
61
|
it "uses the specified http_client" do
|
|
62
62
|
product = create(:product)
|
|
63
|
+
url = ProductIndex.connection.version.to_i < 8 ? ProductIndex.type_url : ProductIndex.index_url
|
|
63
64
|
|
|
64
|
-
stub_request(:put, "#{
|
|
65
|
-
.with(headers: { "X-Header" => "Value" })
|
|
66
|
-
.to_return(status: 500)
|
|
65
|
+
stub_request(:put, "#{url}/_bulk").with(headers: { "X-Header" => "Value" }).to_return(status: 200, body: "{}")
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
bulk.index product.id, ProductIndex.serialize(product)
|
|
71
|
-
end
|
|
67
|
+
ProductIndex.bulk http_client: ProductIndex.connection.http_client.headers("X-Header" => "Value") do |bulk|
|
|
68
|
+
bulk.index product.id, ProductIndex.serialize(product)
|
|
72
69
|
end
|
|
73
70
|
|
|
74
|
-
expect(
|
|
71
|
+
expect(WebMock).to have_requested(:put, "#{url}/_bulk").with(headers: { "X-Header" => "Value" })
|
|
75
72
|
end
|
|
76
73
|
|
|
77
74
|
it "transmits up to bulk_max_mb only" do
|
|
@@ -170,7 +170,7 @@ RSpec.describe SearchFlip::Connection do
|
|
|
170
170
|
it "freezes the specified index" do
|
|
171
171
|
connection = SearchFlip::Connection.new
|
|
172
172
|
|
|
173
|
-
if connection.version.to_f >= 6.6
|
|
173
|
+
if connection.version.to_f >= 6.6 && connection.version.to_i < 8
|
|
174
174
|
begin
|
|
175
175
|
connection.create_index("index_name")
|
|
176
176
|
connection.freeze_index("index_name")
|
|
@@ -187,7 +187,7 @@ RSpec.describe SearchFlip::Connection do
|
|
|
187
187
|
it "unfreezes the specified index" do
|
|
188
188
|
connection = SearchFlip::Connection.new
|
|
189
189
|
|
|
190
|
-
if connection.version.to_f >= 6.6
|
|
190
|
+
if connection.version.to_f >= 6.6 && connection.version.to_i < 8
|
|
191
191
|
begin
|
|
192
192
|
connection.create_index("index_name")
|
|
193
193
|
connection.freeze_index("index_name")
|
|
@@ -262,12 +262,19 @@ RSpec.describe SearchFlip::Connection do
|
|
|
262
262
|
begin
|
|
263
263
|
connection = SearchFlip::Connection.new
|
|
264
264
|
|
|
265
|
-
mapping = { "
|
|
265
|
+
mapping = { "properties" => { "id" => { "type" => "long" } } }
|
|
266
266
|
|
|
267
267
|
connection.create_index("index_name")
|
|
268
|
-
connection.update_mapping("index_name", mapping, type_name: "type_name")
|
|
269
268
|
|
|
270
|
-
|
|
269
|
+
if connection.version.to_i < 8
|
|
270
|
+
connection.update_mapping("index_name", { "type_name" => mapping }, type_name: "type_name")
|
|
271
|
+
|
|
272
|
+
expect(connection.get_mapping("index_name", type_name: "type_name")).to eq("index_name" => { "mappings" => { "type_name" => mapping } })
|
|
273
|
+
else
|
|
274
|
+
connection.update_mapping("index_name", mapping)
|
|
275
|
+
|
|
276
|
+
expect(connection.get_mapping("index_name")).to eq("index_name" => { "mappings" => mapping })
|
|
277
|
+
end
|
|
271
278
|
ensure
|
|
272
279
|
connection.delete_index("index_name") if connection.index_exists?("index_name")
|
|
273
280
|
end
|
|
@@ -1350,28 +1350,40 @@ RSpec.describe SearchFlip::Criteria do
|
|
|
1350
1350
|
|
|
1351
1351
|
describe "#preference" do
|
|
1352
1352
|
it "sets the preference" do
|
|
1353
|
-
|
|
1353
|
+
url = ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"
|
|
1354
|
+
|
|
1355
|
+
stub_request(:post, "http://127.0.0.1:9200/#{url}/_search?preference=value")
|
|
1354
1356
|
.to_return(status: 200, headers: { content_type: "application/json" }, body: "{}")
|
|
1355
1357
|
|
|
1356
1358
|
ProductIndex.preference("value").execute
|
|
1359
|
+
|
|
1360
|
+
expect(WebMock).to have_requested(:post, "http://127.0.0.1:9200/#{url}/_search?preference=value")
|
|
1357
1361
|
end
|
|
1358
1362
|
end
|
|
1359
1363
|
|
|
1360
1364
|
describe "#search_type" do
|
|
1361
1365
|
it "sets the search_type" do
|
|
1362
|
-
|
|
1366
|
+
url = ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"
|
|
1367
|
+
|
|
1368
|
+
stub_request(:post, "http://127.0.0.1:9200/#{url}/_search?search_type=value")
|
|
1363
1369
|
.to_return(status: 200, headers: { content_type: "application/json" }, body: "{}")
|
|
1364
1370
|
|
|
1365
1371
|
ProductIndex.search_type("value").execute
|
|
1372
|
+
|
|
1373
|
+
expect(WebMock).to have_requested(:post, "http://127.0.0.1:9200/#{url}/_search?search_type=value")
|
|
1366
1374
|
end
|
|
1367
1375
|
end
|
|
1368
1376
|
|
|
1369
1377
|
describe "#routing" do
|
|
1370
1378
|
it "sets the search_type" do
|
|
1371
|
-
|
|
1379
|
+
url = ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"
|
|
1380
|
+
|
|
1381
|
+
stub_request(:post, "http://127.0.0.1:9200/#{url}/_search?routing=value")
|
|
1372
1382
|
.to_return(status: 200, headers: { content_type: "application/json" }, body: "{}")
|
|
1373
1383
|
|
|
1374
1384
|
ProductIndex.routing("value").execute
|
|
1385
|
+
|
|
1386
|
+
expect(WebMock).to have_requested(:post, "http://127.0.0.1:9200/#{url}/_search?routing=value")
|
|
1375
1387
|
end
|
|
1376
1388
|
end
|
|
1377
1389
|
end
|
|
@@ -215,7 +215,11 @@ RSpec.describe SearchFlip::Index do
|
|
|
215
215
|
|
|
216
216
|
TestIndex.update_mapping
|
|
217
217
|
|
|
218
|
-
|
|
218
|
+
if TestIndex.connection.version.to_i < 8
|
|
219
|
+
expect(TestIndex.connection).to have_received(:update_mapping).with("test", { "test" => mapping }, type_name: "test")
|
|
220
|
+
else
|
|
221
|
+
expect(TestIndex.connection).to have_received(:update_mapping).with("test", mapping)
|
|
222
|
+
end
|
|
219
223
|
end
|
|
220
224
|
|
|
221
225
|
it "updates the mapping" do
|
|
@@ -268,7 +272,11 @@ RSpec.describe SearchFlip::Index do
|
|
|
268
272
|
|
|
269
273
|
TestIndex.get_mapping
|
|
270
274
|
|
|
271
|
-
|
|
275
|
+
if TestIndex.connection.version.to_i < 8
|
|
276
|
+
expect(TestIndex.connection).to have_received(:get_mapping).with("test", type_name: "test")
|
|
277
|
+
else
|
|
278
|
+
expect(TestIndex.connection).to have_received(:get_mapping).with("test")
|
|
279
|
+
end
|
|
272
280
|
end
|
|
273
281
|
|
|
274
282
|
it "returns the mapping" do
|
|
@@ -332,7 +340,7 @@ RSpec.describe SearchFlip::Index do
|
|
|
332
340
|
|
|
333
341
|
TestIndex.type_url
|
|
334
342
|
|
|
335
|
-
expect(TestIndex.connection).to have_received(:type_url).with("test", "test")
|
|
343
|
+
expect(TestIndex.connection).to have_received(:type_url).with("test", TestIndex.connection.version.to_i < 8 ? "test" : "_doc")
|
|
336
344
|
end
|
|
337
345
|
end
|
|
338
346
|
|
data/spec/spec_helper.rb
CHANGED
|
@@ -84,7 +84,7 @@ class CommentIndex
|
|
|
84
84
|
include SearchFlip::Index
|
|
85
85
|
|
|
86
86
|
def self.type_name
|
|
87
|
-
"comments"
|
|
87
|
+
connection.version.to_i < 8 ? "comments" : "_doc"
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
def self.index_name
|
|
@@ -134,7 +134,7 @@ class ProductIndex
|
|
|
134
134
|
end
|
|
135
135
|
|
|
136
136
|
def self.type_name
|
|
137
|
-
"products"
|
|
137
|
+
connection.version.to_i < 8 ? "products" : "_doc"
|
|
138
138
|
end
|
|
139
139
|
|
|
140
140
|
def self.index_name
|
|
@@ -175,7 +175,7 @@ class TestIndex
|
|
|
175
175
|
end
|
|
176
176
|
|
|
177
177
|
def self.type_name
|
|
178
|
-
"test"
|
|
178
|
+
connection.version.to_i < 8 ? "test" : "_doc"
|
|
179
179
|
end
|
|
180
180
|
|
|
181
181
|
def self.index_name
|
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: 3.
|
|
4
|
+
version: 3.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Benjamin Vetter
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-03-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -302,7 +302,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
302
302
|
version: '0'
|
|
303
303
|
requirements: []
|
|
304
304
|
rubygems_version: 3.2.3
|
|
305
|
-
signing_key:
|
|
305
|
+
signing_key:
|
|
306
306
|
specification_version: 4
|
|
307
307
|
summary: Full-Featured Elasticsearch Ruby Client with a Chainable DSL
|
|
308
308
|
test_files:
|