search_flip 4.0.0.beta9 → 4.0.0.beta10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1850108a3752d6b01de4e2c23453220ac0cf8cd1e4dd61339faeba1c66856960
4
- data.tar.gz: 71b704481fa26e973929c19c9c7df25685b83b65e5ef470ed032531e7fb3fec6
3
+ metadata.gz: ef717835cd3022f20a81919662e6fa217d2ec51ba038dbf47adb8c306263cecd
4
+ data.tar.gz: d4b7809f264bea9b0fa2b2f620bbe017798dc188078d76822baf55f42663ff07
5
5
  SHA512:
6
- metadata.gz: 0d57dc4c3aa5c7ffd9f287bf0ed2b097eb21671a32721fea1daad735c647f8d9d8d01e78c00e9c63d222d587be19246f8cbed85c2fbbc54b2f3a32bcc447b545
7
- data.tar.gz: fc2b76b6f04b94a3843d3f0f8d10a131bc88ea576de7576879d9f6a5d490b2cb0e84b8ff8fee87107b1cf5f7c4a3c8ff84ade40bcadbdb4811bbf0f05088b69c
6
+ metadata.gz: 6a03decbd40819248b0ed6c873f5fd876e97fc1fe2fca501ba71bffe833bcf9ba907360de08b10409fc8d59ff1859ad333ebb7c9e7f6533992baa61c91166221
7
+ data.tar.gz: 9933d1b3f3eca29cee34f2145967b2cd9fe84d313caf95927bd1ec0ac3cdd438dc4b1f0ee04dbada71682a70274b595e422141d8b5e4a4a74677f2119e7fd225
@@ -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
@@ -3,6 +3,9 @@ AllCops:
3
3
  TargetRubyVersion: 2.5
4
4
  SuggestExtensions: false
5
5
 
6
+ Gemspec/RequireMFA:
7
+ Enabled: false
8
+
6
9
  Style/CaseLikeIf:
7
10
  Enabled: false
8
11
 
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.6.0
15
+
16
+ * Support Elasticsearch v8
17
+
14
18
  ## v3.5.0
15
19
 
16
20
  * Add `SearchFlip::Criteria#http_timeout` to allow specifying timeouts on
data/docker-compose.yml CHANGED
@@ -4,5 +4,6 @@ services:
4
4
  image: $ES_IMAGE
5
5
  environment:
6
6
  - discovery.type=single-node
7
+ - xpack.security.enabled=false
7
8
  ports:
8
9
  - 9200:9200
@@ -93,7 +93,7 @@ module SearchFlip
93
93
  def msearch(criterias)
94
94
  payload = criterias.flat_map do |criteria|
95
95
  [
96
- SearchFlip::JSON.generate(index: criteria.target.index_name_with_prefix, type: criteria.target.type_name),
96
+ SearchFlip::JSON.generate(index: criteria.target.index_name_with_prefix, **(version.to_i < 8 ? { type: criteria.target.type_name } : {})),
97
97
  SearchFlip::JSON.generate(criteria.request)
98
98
  ]
99
99
  end
@@ -329,8 +329,8 @@ module SearchFlip
329
329
  # @return [Boolean] Returns true or raises SearchFlip::ResponseError
330
330
 
331
331
  def update_mapping(index_name, mapping, type_name: nil)
332
- url = type_name ? type_url(index_name, type_name) : index_url(index_name)
333
- params = type_name && version.to_f >= 6.7 ? { include_type_name: true } : {}
332
+ url = type_name && version.to_i < 8 ? type_url(index_name, type_name) : index_url(index_name)
333
+ params = type_name && version.to_f >= 6.7 && version.to_i < 8 ? { include_type_name: true } : {}
334
334
 
335
335
  http_client.put("#{url}/_mapping", params: params, json: mapping)
336
336
 
@@ -347,8 +347,8 @@ module SearchFlip
347
347
  # @return [Hash] The current type mapping
348
348
 
349
349
  def get_mapping(index_name, type_name: nil)
350
- url = type_name ? type_url(index_name, type_name) : index_url(index_name)
351
- params = type_name && version.to_f >= 6.7 ? { include_type_name: true } : {}
350
+ url = type_name && version.to_i < 8 ? type_url(index_name, type_name) : index_url(index_name)
351
+ params = type_name && version.to_f >= 6.7 && version.to_i < 8 ? { include_type_name: true } : {}
352
352
 
353
353
  response = http_client.headers(accept: "application/json").get("#{url}/_mapping", params: params)
354
354
 
@@ -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
- http_request.post("#{target.type_url}/_delete_by_query", params: request_params.merge(params), json: dupped_request)
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
- "#{target.type_url}/_search",
628
+ "#{url}/_search",
625
629
  params: request_params.merge(scroll: scroll_args[:timeout]),
626
630
  json: request
627
631
  )
628
632
  else
629
- http_request.post("#{target.type_url}/_search", params: request_params, json: request)
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))
@@ -455,7 +455,8 @@ module SearchFlip
455
455
  # @return [Hash] The specified document
456
456
 
457
457
  def get(id, params = {})
458
- response = connection.http_client.headers(accept: "application/json").get("#{type_url}/#{id}", params: params)
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
- response = connection.http_client.headers(accept: "application/json").post("#{type_url}/_mget", json: request, params: params)
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
- SearchFlip::Bulk.new("#{type_url}/_bulk", default_options.merge(options)) do |indexer|
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
 
@@ -1,3 +1,3 @@
1
1
  module SearchFlip
2
- VERSION = "4.0.0.beta9"
2
+ VERSION = "4.0.0.beta10"
3
3
  end
@@ -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
- "host" => "localhost",
20
- "authorization" => /.*/,
21
- "x-amz-content-sha256" => /.*/,
22
- "x-amz-date" => /20200101T120000Z/
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, "#{ProductIndex.type_url}/_bulk")
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
- block = lambda do
69
- ProductIndex.bulk http_client: ProductIndex.connection.http_client.headers("X-Header" => "Value") do |bulk|
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(&block).to raise_error(SearchFlip::ResponseError)
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
@@ -199,7 +199,7 @@ RSpec.describe SearchFlip::Connection do
199
199
  it "freezes the specified index" do
200
200
  connection = SearchFlip::Connection.new
201
201
 
202
- if connection.version.to_f >= 6.6
202
+ if connection.version.to_f >= 6.6 && connection.version.to_i < 8
203
203
  begin
204
204
  connection.create_index("index_name")
205
205
  connection.freeze_index("index_name")
@@ -216,7 +216,7 @@ RSpec.describe SearchFlip::Connection do
216
216
  it "unfreezes the specified index" do
217
217
  connection = SearchFlip::Connection.new
218
218
 
219
- if connection.version.to_f >= 6.6
219
+ if connection.version.to_f >= 6.6 && connection.version.to_i < 8
220
220
  begin
221
221
  connection.create_index("index_name")
222
222
  connection.freeze_index("index_name")
@@ -291,12 +291,19 @@ RSpec.describe SearchFlip::Connection do
291
291
  begin
292
292
  connection = SearchFlip::Connection.new
293
293
 
294
- mapping = { "type_name" => { "properties" => { "id" => { "type" => "long" } } } }
294
+ mapping = { "properties" => { "id" => { "type" => "long" } } }
295
295
 
296
296
  connection.create_index("index_name")
297
- connection.update_mapping("index_name", mapping, type_name: "type_name")
298
297
 
299
- expect(connection.get_mapping("index_name", type_name: "type_name")).to eq("index_name" => { "mappings" => mapping })
298
+ if connection.version.to_i < 8
299
+ connection.update_mapping("index_name", { "type_name" => mapping }, type_name: "type_name")
300
+
301
+ expect(connection.get_mapping("index_name", type_name: "type_name")).to eq("index_name" => { "mappings" => { "type_name" => mapping } })
302
+ else
303
+ connection.update_mapping("index_name", mapping)
304
+
305
+ expect(connection.get_mapping("index_name")).to eq("index_name" => { "mappings" => mapping })
306
+ end
300
307
  ensure
301
308
  connection.delete_index("index_name") if connection.index_exists?("index_name")
302
309
  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
- stub_request(:post, "http://127.0.0.1:9200/products/products/_search?preference=value")
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
- stub_request(:post, "http://127.0.0.1:9200/products/products/_search?search_type=value")
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
- stub_request(:post, "http://127.0.0.1:9200/products/products/_search?routing=value")
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
- expect(TestIndex.connection).to have_received(:update_mapping).with("test", { "test" => mapping }, type_name: "test")
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
- expect(TestIndex.connection).to have_received(:get_mapping).with("test", type_name: "test")
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: 4.0.0.beta9
4
+ version: 4.0.0.beta10
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: 2021-07-30 00:00:00.000000000 Z
11
+ date: 2022-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -288,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
288
288
  version: 1.3.1
289
289
  requirements: []
290
290
  rubygems_version: 3.2.3
291
- signing_key:
291
+ signing_key:
292
292
  specification_version: 4
293
293
  summary: Full-Featured Elasticsearch Ruby Client with a Chainable DSL
294
294
  test_files: