search_flip 3.7.2 → 3.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8c5d0e833c92cf4584fe620634d0c2633cc82248a5cae91c256799d280057f5
4
- data.tar.gz: 62f5f4944c3a1dc823f75f9bcede05c69ab103d19ae19cfec8f3c518a3829723
3
+ metadata.gz: 84f5374ca017b59ee706e4e6e06c9739c18a83395ded6df0628b234d0e129e39
4
+ data.tar.gz: 1f6e1dd1a76f69b8cb552387add7d1dfe2b367739c38a7b9260db0c9954b8e26
5
5
  SHA512:
6
- metadata.gz: 5480c57d7d814d96903aab184a82831d4f78d3613249eb8c6951992deaf873bba00ee3d5f8053050775973ac70cb2fc4665b7b15503634b53e853b8d0c29b198
7
- data.tar.gz: 648f80a25a38e6ec50ab3ecec25a4b6dee92902804c6ee82409d7084c27527cea9788458f5e674dcbf2d0eea5aef401a13e3f1a3b23bd2e6ef1c5659e3a915d3
6
+ metadata.gz: 283b816aa7602cb4ffb1c981421e7fb13353158f40de052daec3c6c6700b42ff2b19eeb6accb22b8dcc29cf4589caf8c4a01edd827bc055eb97e16c6ed3ba972
7
+ data.tar.gz: a63de18588ef4b93c38eb7b4bfb91135f73e027f21371ff46c053dfbadb207661008aa5b31d05ac6e62298539e73cdf5c8421bb6aff93f2369f2712724bcd7f8
@@ -7,30 +7,58 @@ jobs:
7
7
  fail-fast: false
8
8
  matrix:
9
9
  elasticsearch:
10
- - plainpicture/elasticsearch:2.4.1_delete-by-query
11
- - elasticsearch:5.4
12
- - docker.elastic.co/elasticsearch/elasticsearch:6.7.0
13
- - docker.elastic.co/elasticsearch/elasticsearch:7.0.0
14
- - docker.elastic.co/elasticsearch/elasticsearch:7.11.2
15
- - docker.elastic.co/elasticsearch/elasticsearch:8.1.1
10
+ - image: plainpicture/elasticsearch:2.4.1_delete-by-query
11
+ env:
12
+ discovery.type: single-node
13
+ xpack.security.enabled: false
14
+ - image: elasticsearch:5.4
15
+ env:
16
+ discovery.type: single-node
17
+ xpack.security.enabled: false
18
+ - image: docker.elastic.co/elasticsearch/elasticsearch:6.7.0
19
+ env:
20
+ discovery.type: single-node
21
+ xpack.security.enabled: false
22
+ - image: docker.elastic.co/elasticsearch/elasticsearch:7.0.0
23
+ env:
24
+ discovery.type: single-node
25
+ xpack.security.enabled: false
26
+ - image: docker.elastic.co/elasticsearch/elasticsearch:7.11.2
27
+ env:
28
+ discovery.type: single-node
29
+ xpack.security.enabled: false
30
+ - image: docker.elastic.co/elasticsearch/elasticsearch:8.1.1
31
+ env:
32
+ discovery.type: single-node
33
+ xpack.security.enabled: false
34
+ - image: opensearchproject/opensearch:1.3.14
35
+ env:
36
+ discovery.type: single-node
37
+ plugins.security.disabled: true
38
+ - image: opensearchproject/opensearch:2.11.1
39
+ env:
40
+ discovery.type: single-node
41
+ plugins.security.disabled: true
42
+ - image: opensearchproject/opensearch:2.13.0
43
+ env:
44
+ discovery.type: single-node
45
+ DISABLE_SECURITY_PLUGIN: true
16
46
  ruby:
17
- - 2.6
18
47
  - 2.7
19
48
  - 3.0
49
+ - 3.1
50
+ - 3.2
20
51
  services:
21
52
  elasticsearch:
22
- image: ${{ matrix.elasticsearch }}
23
- env:
24
- discovery.type: single-node
25
- xpack.security.enabled: false
53
+ image: ${{ matrix.elasticsearch.image }}
54
+ env: ${{ matrix.elasticsearch.env }}
26
55
  ports:
27
56
  - 9200:9200
28
57
  steps:
29
58
  - uses: actions/checkout@v1
30
- - uses: actions/setup-ruby@v1
59
+ - uses: ruby/setup-ruby@v1
31
60
  with:
32
61
  ruby-version: ${{ matrix.ruby }}
33
- - run: gem install bundler
34
62
  - run: bundle
35
63
  - run: bundle exec rspec
36
64
  - run: bundle exec rubocop
data/CHANGELOG.md CHANGED
@@ -1,6 +1,23 @@
1
1
 
2
2
  # CHANGELOG
3
3
 
4
+ ## v3.9.0
5
+
6
+ * Allow to configure the elasticsearch version no matter which elasticsearch
7
+ version is actually in use. The version information is needed to support
8
+ version dependent features. Please note that manually configuring the version
9
+ is usually not need as the version by default is determined by sending one
10
+ request to elasticsearch.
11
+
12
+ ```ruby
13
+ SearchFlip::Config[:version] = { number: "8.1.1" }
14
+ SearchFlip::Config[:version] = { number: "2.13", distribution: "opensearch" }
15
+ ```
16
+
17
+ ## v3.8.0
18
+
19
+ * Support Opensearch 1.x and 2.x
20
+
4
21
  ## v3.7.2
5
22
 
6
23
  * Fix wrong AWS signatures by generating the json before passing it to http-rb
data/Gemfile CHANGED
@@ -2,4 +2,18 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem "activerecord", "< 5" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.2.2")
5
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.2.2")
6
+ gem "activerecord", ">= 3.0", "< 5"
7
+ else
8
+ gem "activerecord", ">= 3.0"
9
+ end
10
+
11
+ gem "aws-sdk-core"
12
+ gem "bundler"
13
+ gem "factory_bot"
14
+ gem "rake"
15
+ gem "rspec"
16
+ gem "rubocop"
17
+ gem "sqlite3", "~> 1.4"
18
+ gem "timecop"
19
+ gem "webmock"
data/README.md CHANGED
@@ -9,8 +9,9 @@
9
9
  Using SearchFlip it is dead-simple to create index classes that correspond to
10
10
  [Elasticsearch](https://www.elastic.co/) indices and to manipulate, query and
11
11
  aggregate these indices using a chainable, concise, yet powerful DSL. Finally,
12
- SearchFlip supports Elasticsearch 2.x, 5.x, 6.x, 7.x and 8.x. Check section
13
- [Feature Support](#feature-support) for version dependent features.
12
+ SearchFlip supports Elasticsearch 2.x, 5.x, 6.x, 7.x and 8.x as well as
13
+ Opensearch 1.x and 2.x. Check section [Feature Support](#feature-support) for
14
+ version dependent features.
14
15
 
15
16
  ```ruby
16
17
  CommentIndex.search("hello world", default_field: "title").where(visible: true).aggregate(:user_id).sort(id: "desc")
@@ -97,6 +98,16 @@ Available config options are:
97
98
  * `auto_refresh` tells SearchFlip to automatically refresh an index after
98
99
  import, index, delete, etc operations. This is e.g. useful for testing, etc.
99
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
+ ```
100
111
 
101
112
  ## Usage
102
113
 
@@ -852,7 +863,7 @@ performance tracing, etc.
852
863
  To use instrumentation, configure the instrumenter:
853
864
 
854
865
  ```ruby
855
- SearchFlip::Config[:instrumenter] = ActiveSupport::Notifications.notifier
866
+ SearchFlip::Config[:instrumenter] = ActiveSupport::Notifications
856
867
  ```
857
868
 
858
869
  Subsequently, you can subscribe to notifcations for `request.search_flip`:
@@ -970,7 +981,6 @@ SearchFlip is using Semantic Versioning: [SemVer](http://semver.org/)
970
981
 
971
982
  * Elasticsearch: [https://www.elastic.co/](https://www.elastic.co/)
972
983
  * Reference Docs: [http://www.rubydoc.info/github/mrkamel/search_flip](http://www.rubydoc.info/github/mrkamel/search_flip)
973
- * Travis: [http://travis-ci.org/mrkamel/search_flip](http://travis-ci.org/mrkamel/search_flip)
974
984
  * will_paginate: [https://github.com/mislav/will_paginate](https://github.com/mislav/will_paginate)
975
985
  * kaminari: [https://github.com/kaminari/kaminari](https://github.com/kaminari/kaminari)
976
986
  * Oj: [https://github.com/ohler55/oj](https://github.com/ohler55/oj)
@@ -30,7 +30,7 @@ module SearchFlip
30
30
  res[:aggregations] = aggregation_values if aggregation_values
31
31
 
32
32
  if must_values || must_not_values || filter_values
33
- if target.connection.version.to_i >= 2
33
+ if target.connection.distribution || target.connection.version.to_i >= 2
34
34
  res[:filter] = {
35
35
  bool: {}
36
36
  .merge(must_values ? { must: must_values } : {})
@@ -148,7 +148,7 @@ module SearchFlip
148
148
  return unless parsed_response["errors"]
149
149
 
150
150
  parsed_response["items"].each do |item|
151
- item.each do |_, element|
151
+ item.each_value do |element|
152
152
  status = element["status"]
153
153
 
154
154
  next if status.between?(200, 299)
@@ -16,24 +16,28 @@ module SearchFlip
16
16
  @base_url = options[:base_url] || SearchFlip::Config[:base_url]
17
17
  @http_client = options[:http_client] || SearchFlip::HTTPClient.new
18
18
  @bulk_limit = options[:bulk_limit] || SearchFlip::Config[:bulk_limit]
19
- @version_mutex = Mutex.new
19
+ end
20
+
21
+ # Queries and returns the Elasticsearch distribution used.
22
+ #
23
+ # @example
24
+ # connection.distribution # => e.g. "opensearch"
25
+ #
26
+ # @return [String] The Elasticsearch distribution
27
+
28
+ def distribution
29
+ @distribution ||= SearchFlip::Config.dig(:version, :distribution) || SearchFlip::JSON.parse(version_response.to_s)["version"]["distribution"]
20
30
  end
21
31
 
22
32
  # Queries and returns the Elasticsearch version used.
23
33
  #
24
34
  # @example
25
- # connection.version # => e.g. 2.4.1
35
+ # connection.version # => e.g. "2.4.1"
26
36
  #
27
37
  # @return [String] The Elasticsearch version
28
38
 
29
39
  def version
30
- @version_mutex.synchronize do
31
- @version ||= begin
32
- response = http_client.headers(accept: "application/json").get("#{base_url}/")
33
-
34
- SearchFlip::JSON.parse(response.to_s)["version"]["number"]
35
- end
36
- end
40
+ @version ||= SearchFlip::Config.dig(:version, :number) || SearchFlip::JSON.parse(version_response.to_s)["version"]["number"]
37
41
  end
38
42
 
39
43
  # Queries and returns the Elasticsearch cluster health.
@@ -64,7 +68,7 @@ module SearchFlip
64
68
  def msearch(criterias)
65
69
  payload = criterias.flat_map do |criteria|
66
70
  [
67
- SearchFlip::JSON.generate(index: criteria.target.index_name_with_prefix, **(version.to_i < 8 ? { type: criteria.target.type_name } : {})),
71
+ SearchFlip::JSON.generate(index: criteria.target.index_name_with_prefix, **(distribution.nil? && version.to_i < 8 ? { type: criteria.target.type_name } : {})),
68
72
  SearchFlip::JSON.generate(criteria.request)
69
73
  ]
70
74
  end
@@ -300,8 +304,8 @@ module SearchFlip
300
304
  # @return [Boolean] Returns true or raises SearchFlip::ResponseError
301
305
 
302
306
  def update_mapping(index_name, mapping, type_name: nil)
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 } : {}
307
+ url = type_name && distribution.nil? && version.to_i < 8 ? type_url(index_name, type_name) : index_url(index_name)
308
+ params = type_name && distribution.nil? && version.to_f >= 6.7 && version.to_i < 8 ? { include_type_name: true } : {}
305
309
 
306
310
  http_client.put("#{url}/_mapping", params: params, json: mapping)
307
311
 
@@ -318,8 +322,8 @@ module SearchFlip
318
322
  # @return [Hash] The current type mapping
319
323
 
320
324
  def get_mapping(index_name, type_name: nil)
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 } : {}
325
+ url = type_name && distribution.nil? && version.to_i < 8 ? type_url(index_name, type_name) : index_url(index_name)
326
+ params = type_name && distribution.nil? && version.to_f >= 6.7 && version.to_i < 8 ? { include_type_name: true } : {}
323
327
 
324
328
  response = http_client.headers(accept: "application/json").get("#{url}/_mapping", params: params)
325
329
 
@@ -422,5 +426,11 @@ module SearchFlip
422
426
  def index_url(index_name)
423
427
  "#{base_url}/#{index_name}"
424
428
  end
429
+
430
+ private
431
+
432
+ def version_response
433
+ @version_response ||= http_client.headers(accept: "application/json").get("#{base_url}/")
434
+ end
425
435
  end
426
436
  end
@@ -350,8 +350,8 @@ module SearchFlip
350
350
  http_request = connection.http_client
351
351
  http_request = http_request.timeout(http_timeout_value) if http_timeout_value
352
352
 
353
- if connection.version.to_i >= 5
354
- url = connection.version.to_i < 8 ? target.type_url : target.index_url
353
+ if connection.distribution || connection.version.to_i >= 5
354
+ url = connection.distribution.nil? && connection.version.to_i < 8 ? target.type_url : target.index_url
355
355
 
356
356
  http_request.post("#{url}/_delete_by_query", params: request_params.merge(params), json: dupped_request)
357
357
  else
@@ -622,7 +622,7 @@ module SearchFlip
622
622
  json: { scroll: scroll_args[:timeout], scroll_id: scroll_args[:id] }
623
623
  )
624
624
  elsif scroll_args
625
- url = connection.version.to_i < 8 ? target.type_url : target.index_url
625
+ url = connection.distribution.nil? && connection.version.to_i < 8 ? target.type_url : target.index_url
626
626
 
627
627
  http_request.post(
628
628
  "#{url}/_search",
@@ -630,7 +630,7 @@ module SearchFlip
630
630
  json: request
631
631
  )
632
632
  else
633
- url = connection.version.to_i < 8 ? target.type_url : target.index_url
633
+ url = connection.distribution.nil? && connection.version.to_i < 8 ? target.type_url : target.index_url
634
634
 
635
635
  http_request.post("#{url}/_search", params: request_params, json: request)
636
636
  end
@@ -438,7 +438,7 @@ module SearchFlip
438
438
  # equal to _doc.
439
439
 
440
440
  def include_type_name?
441
- type_name != "_doc" || connection.version.to_i < 7
441
+ type_name != "_doc" || (connection.distribution.nil? && connection.version.to_i < 7)
442
442
  end
443
443
 
444
444
  # Retrieves the document specified by id from Elasticsearch. Raises
@@ -455,7 +455,7 @@ module SearchFlip
455
455
  # @return [Hash] The specified document
456
456
 
457
457
  def get(id, params = {})
458
- url = connection.version.to_i < 8 ? type_url : "#{index_url}/_doc"
458
+ url = connection.distribution.nil? && connection.version.to_i < 8 ? type_url : "#{index_url}/_doc"
459
459
  response = connection.http_client.headers(accept: "application/json").get("#{url}/#{id}", params: params)
460
460
 
461
461
  SearchFlip::JSON.parse(response.to_s)
@@ -474,7 +474,7 @@ module SearchFlip
474
474
  # @return [Hash] The raw response
475
475
 
476
476
  def mget(request, params = {})
477
- url = connection.version.to_i < 8 ? type_url : index_url
477
+ url = connection.distribution.nil? && connection.version.to_i < 8 ? type_url : index_url
478
478
  response = connection.http_client.headers(accept: "application/json").post("#{url}/_mget", json: request, params: params)
479
479
 
480
480
  SearchFlip::JSON.parse(response.to_s)
@@ -633,7 +633,7 @@ module SearchFlip
633
633
  bulk_max_mb: connection.bulk_max_mb
634
634
  }
635
635
 
636
- url = connection.version.to_i < 8 ? type_url : index_url
636
+ url = connection.distribution.nil? && connection.version.to_i < 8 ? type_url : index_url
637
637
 
638
638
  SearchFlip::Bulk.new("#{url}/_bulk", default_options.merge(options)) do |indexer|
639
639
  yield indexer
@@ -224,7 +224,7 @@ module SearchFlip
224
224
 
225
225
  def records
226
226
  @records ||= begin
227
- sort_map = ids.each_with_index.each_with_object({}) { |(id, index), hash| hash[id.to_s] = index }
227
+ sort_map = ids.each_with_index.with_object({}) { |(id, index), hash| hash[id.to_s] = index }
228
228
 
229
229
  scope.to_a.sort_by { |record| sort_map[criteria.target.record_id(record).to_s] }
230
230
  end
@@ -1,3 +1,3 @@
1
1
  module SearchFlip
2
- VERSION = "3.7.2"
2
+ VERSION = "3.9.0"
3
3
  end
data/search_flip.gemspec CHANGED
@@ -13,6 +13,10 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/mrkamel/search_flip"
14
14
  spec.license = "MIT"
15
15
 
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/mrkamel/search_flip"
18
+ spec.metadata["changelog_uri"] = "https://github.com/mrkamel/search_flip/blob/master/CHANGELOG.md"
19
+
16
20
  spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
21
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
22
  spec.require_paths = ["lib"]
@@ -23,17 +27,6 @@ Gem::Specification.new do |spec|
23
27
  https://github.com/mrkamel/search_flip/blob/master/UPDATING.md
24
28
  MESSAGE
25
29
 
26
- spec.add_development_dependency "activerecord", ">= 3.0"
27
- spec.add_development_dependency "aws-sdk-core"
28
- spec.add_development_dependency "bundler"
29
- spec.add_development_dependency "factory_bot"
30
- spec.add_development_dependency "rake"
31
- spec.add_development_dependency "rspec"
32
- spec.add_development_dependency "rubocop"
33
- spec.add_development_dependency "sqlite3"
34
- spec.add_development_dependency "timecop"
35
- spec.add_development_dependency "webmock"
36
-
37
30
  spec.add_dependency "hashie"
38
31
  spec.add_dependency "http"
39
32
  spec.add_dependency "json"
@@ -60,7 +60,7 @@ 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
+ url = ProductIndex.connection.distribution.nil? && ProductIndex.connection.version.to_i < 8 ? ProductIndex.type_url : ProductIndex.index_url
64
64
 
65
65
  stub_request(:put, "#{url}/_bulk").with(headers: { "X-Header" => "Value" }).to_return(status: 200, body: "{}")
66
66
 
@@ -1,10 +1,32 @@
1
1
  require File.expand_path("../spec_helper", __dir__)
2
2
 
3
3
  RSpec.describe SearchFlip::Connection do
4
+ describe "#distribution" do
5
+ it "reutrns the distribution" do
6
+ expect([nil, "opensearch"]).to include(SearchFlip::Connection.new.distribution)
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
16
+ end
17
+
4
18
  describe "#version" do
5
19
  it "returns the version" do
6
20
  expect(SearchFlip::Connection.new.version).to match(/\A[0-9.]+\z/)
7
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
8
30
  end
9
31
 
10
32
  describe "#cluster_health" do
@@ -92,7 +114,7 @@ RSpec.describe SearchFlip::Connection do
92
114
  it "returns the specified indices" do
93
115
  connection = SearchFlip::Connection.new
94
116
 
95
- expect(connection.get_indices.map { |index| index["index"] }.to_set).to eq(["comments", "products"].to_set)
117
+ expect(connection.get_indices.map { |index| index["index"] }.grep_v(/^\./).to_set).to eq(["comments", "products"].to_set)
96
118
  expect(connection.get_indices("com*").map { |index| index["index"] }).to eq(["comments"])
97
119
  end
98
120
 
@@ -170,7 +192,7 @@ RSpec.describe SearchFlip::Connection do
170
192
  it "freezes the specified index" do
171
193
  connection = SearchFlip::Connection.new
172
194
 
173
- if connection.version.to_f >= 6.6 && connection.version.to_i < 8
195
+ if connection.distribution.nil? && connection.version.to_f >= 6.6 && connection.version.to_i < 8
174
196
  begin
175
197
  connection.create_index("index_name")
176
198
  connection.freeze_index("index_name")
@@ -187,7 +209,7 @@ RSpec.describe SearchFlip::Connection do
187
209
  it "unfreezes the specified index" do
188
210
  connection = SearchFlip::Connection.new
189
211
 
190
- if connection.version.to_f >= 6.6 && connection.version.to_i < 8
212
+ if connection.distribution.nil? && connection.version.to_f >= 6.6 && connection.version.to_i < 8
191
213
  begin
192
214
  connection.create_index("index_name")
193
215
  connection.freeze_index("index_name")
@@ -241,7 +263,7 @@ RSpec.describe SearchFlip::Connection do
241
263
  end
242
264
 
243
265
  describe "#update_mapping" do
244
- if SearchFlip::Connection.new.version.to_i >= 7
266
+ if SearchFlip::Connection.new.then { |connection| connection.distribution || connection.version.to_i >= 7 }
245
267
  it "updates the mapping of an index without type name" do
246
268
  begin
247
269
  connection = SearchFlip::Connection.new
@@ -266,7 +288,7 @@ RSpec.describe SearchFlip::Connection do
266
288
 
267
289
  connection.create_index("index_name")
268
290
 
269
- if connection.version.to_i < 8
291
+ if connection.distribution.nil? && connection.version.to_i < 8
270
292
  connection.update_mapping("index_name", { "type_name" => mapping }, type_name: "type_name")
271
293
 
272
294
  expect(connection.get_mapping("index_name", type_name: "type_name")).to eq("index_name" => { "mappings" => { "type_name" => mapping } })
@@ -321,9 +343,9 @@ RSpec.describe SearchFlip::Connection do
321
343
 
322
344
  bulk = proc do
323
345
  connection.bulk do |indexer|
324
- indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
325
- indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
326
- indexer.index 1, { id: 1 }, _index: CommentIndex.index_name, ** connection.version.to_i < 8 ? { _type: CommentIndex.type_name } : {}
346
+ indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
347
+ indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
348
+ indexer.index 1, { id: 1 }, _index: CommentIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: CommentIndex.type_name } : {}
327
349
  end
328
350
  end
329
351
 
@@ -346,14 +368,14 @@ RSpec.describe SearchFlip::Connection do
346
368
  connection = SearchFlip::Connection.new
347
369
 
348
370
  connection.bulk do |indexer|
349
- indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
350
- indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
371
+ indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
372
+ indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
351
373
  end
352
374
 
353
375
  bulk = proc do
354
376
  connection.bulk do |indexer|
355
- indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
356
- indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
377
+ indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
378
+ indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
357
379
  end
358
380
  end
359
381
 
@@ -361,8 +383,8 @@ RSpec.describe SearchFlip::Connection do
361
383
 
362
384
  bulk = proc do
363
385
  connection.bulk ignore_errors: [409] do |indexer|
364
- indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
365
- indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
386
+ indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
387
+ indexer.index 2, { id: 2 }, _index: ProductIndex.index_name, version: 1, version_type: "external", ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
366
388
  end
367
389
  end
368
390
 
@@ -375,7 +397,7 @@ RSpec.describe SearchFlip::Connection do
375
397
  connection = SearchFlip::Connection.new
376
398
 
377
399
  connection.bulk do |indexer|
378
- indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
400
+ indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
379
401
  end
380
402
 
381
403
  expect(SearchFlip::Bulk).to have_received(:new).with(
@@ -398,7 +420,7 @@ RSpec.describe SearchFlip::Connection do
398
420
  }
399
421
 
400
422
  connection.bulk(options) do |indexer|
401
- indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
423
+ indexer.index 1, { id: 1 }, _index: ProductIndex.index_name, ** connection.distribution.nil? && connection.version.to_i < 8 ? { _type: ProductIndex.type_name } : {}
402
424
  end
403
425
 
404
426
  expect(SearchFlip::Bulk).to have_received(:new).with(anything, options)
@@ -435,7 +435,7 @@ RSpec.describe SearchFlip::Criteria do
435
435
 
436
436
  describe "#match_none" do
437
437
  it "does not match any documents" do
438
- if ProductIndex.connection.version.to_i >= 5
438
+ if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 5
439
439
  ProductIndex.import create(:product)
440
440
 
441
441
  query = ProductIndex.match_none
@@ -479,7 +479,7 @@ RSpec.describe SearchFlip::Criteria do
479
479
 
480
480
  describe "#post_search" do
481
481
  it "sets up the constraints correctly and is chainable" do
482
- if ProductIndex.connection.version.to_i >= 2
482
+ if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 2
483
483
  product1 = create(:product, title: "title1", category: "category1")
484
484
  product2 = create(:product, title: "title2", category: "category2")
485
485
  product3 = create(:product, title: "title3", category: "category1")
@@ -886,7 +886,7 @@ RSpec.describe SearchFlip::Criteria do
886
886
 
887
887
  describe "#profile" do
888
888
  it "sets up the constraints correctly" do
889
- if ProductIndex.connection.version.to_i >= 2
889
+ if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 2
890
890
  expect(ProductIndex.profile(true).raw_response["profile"]).not_to be_nil
891
891
  end
892
892
  end
@@ -1322,7 +1322,7 @@ RSpec.describe SearchFlip::Criteria do
1322
1322
 
1323
1323
  describe "#track_total_hits" do
1324
1324
  it "is added to the request" do
1325
- if ProductIndex.connection.version.to_i >= 7
1325
+ if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 7
1326
1326
  query = ProductIndex.track_total_hits(false)
1327
1327
 
1328
1328
  expect(query.request[:track_total_hits]).to eq(false)
@@ -1350,7 +1350,7 @@ RSpec.describe SearchFlip::Criteria do
1350
1350
 
1351
1351
  describe "#preference" do
1352
1352
  it "sets the preference" do
1353
- url = ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"
1353
+ url = ProductIndex.connection.distribution.nil? && ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"
1354
1354
 
1355
1355
  stub_request(:post, "http://127.0.0.1:9200/#{url}/_search?preference=value")
1356
1356
  .to_return(status: 200, headers: { content_type: "application/json" }, body: "{}")
@@ -1363,7 +1363,7 @@ RSpec.describe SearchFlip::Criteria do
1363
1363
 
1364
1364
  describe "#search_type" do
1365
1365
  it "sets the search_type" do
1366
- url = ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"
1366
+ url = ProductIndex.connection.distribution.nil? && ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"
1367
1367
 
1368
1368
  stub_request(:post, "http://127.0.0.1:9200/#{url}/_search?search_type=value")
1369
1369
  .to_return(status: 200, headers: { content_type: "application/json" }, body: "{}")
@@ -1376,7 +1376,7 @@ RSpec.describe SearchFlip::Criteria do
1376
1376
 
1377
1377
  describe "#routing" do
1378
1378
  it "sets the search_type" do
1379
- url = ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"
1379
+ url = ProductIndex.connection.distribution.nil? && ProductIndex.connection.version.to_i < 8 ? "products/products" : "products"
1380
1380
 
1381
1381
  stub_request(:post, "http://127.0.0.1:9200/#{url}/_search?routing=value")
1382
1382
  .to_return(status: 200, headers: { content_type: "application/json" }, body: "{}")
@@ -77,7 +77,7 @@ RSpec.describe SearchFlip::Index do
77
77
  include SearchFlip::Index
78
78
  end
79
79
 
80
- expect(klass.include_type_name?).to eq(klass.connection.version.to_i < 7)
80
+ expect(klass.include_type_name?).to eq(klass.connection.distribution.nil? && klass.connection.version.to_i < 7)
81
81
  end
82
82
 
83
83
  it "returns true if the type name is not equal to _doc" do
@@ -185,7 +185,7 @@ RSpec.describe SearchFlip::Index do
185
185
  end
186
186
 
187
187
  describe ".update_mapping" do
188
- if TestIndex.connection.version.to_i >= 7
188
+ if TestIndex.connection.distribution || TestIndex.connection.version.to_i >= 7
189
189
  context "without type name" do
190
190
  it "delegates to connection" do
191
191
  TestIndex.create_index
@@ -215,7 +215,7 @@ RSpec.describe SearchFlip::Index do
215
215
 
216
216
  TestIndex.update_mapping
217
217
 
218
- if TestIndex.connection.version.to_i < 8
218
+ if TestIndex.connection.distribution.nil? && TestIndex.connection.version.to_i < 8
219
219
  expect(TestIndex.connection).to have_received(:update_mapping).with("test", { "test" => mapping }, type_name: "test")
220
220
  else
221
221
  expect(TestIndex.connection).to have_received(:update_mapping).with("test", mapping)
@@ -245,7 +245,7 @@ RSpec.describe SearchFlip::Index do
245
245
  end
246
246
 
247
247
  describe ".get_mapping" do
248
- if TestIndex.connection.version.to_i >= 7
248
+ if TestIndex.connection.distribution || TestIndex.connection.version.to_i >= 7
249
249
  context "without type name" do
250
250
  it "delegates to connection" do
251
251
  allow(TestIndex).to receive(:include_type_name?).and_return(false)
@@ -272,7 +272,7 @@ RSpec.describe SearchFlip::Index do
272
272
 
273
273
  TestIndex.get_mapping
274
274
 
275
- if TestIndex.connection.version.to_i < 8
275
+ if TestIndex.connection.distribution.nil? && TestIndex.connection.version.to_i < 8
276
276
  expect(TestIndex.connection).to have_received(:get_mapping).with("test", type_name: "test")
277
277
  else
278
278
  expect(TestIndex.connection).to have_received(:get_mapping).with("test")
@@ -340,7 +340,7 @@ RSpec.describe SearchFlip::Index do
340
340
 
341
341
  TestIndex.type_url
342
342
 
343
- expect(TestIndex.connection).to have_received(:type_url).with("test", TestIndex.connection.version.to_i < 8 ? "test" : "_doc")
343
+ expect(TestIndex.connection).to have_received(:type_url).with("test", TestIndex.connection.distribution.nil? && TestIndex.connection.version.to_i < 8 ? "test" : "_doc")
344
344
  end
345
345
  end
346
346
 
@@ -433,7 +433,7 @@ RSpec.describe SearchFlip::Index do
433
433
 
434
434
  products = create_list(:product, 2)
435
435
 
436
- if ProductIndex.connection.version.to_i >= 5
436
+ if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 5
437
437
  expect { ProductIndex.create products, {}, routing: "r1" }.to(change { ProductIndex.total_count }.by(2))
438
438
 
439
439
  expect(ProductIndex.get(products.first.id, routing: "r1")["_routing"]).to eq("r1")
@@ -447,7 +447,7 @@ RSpec.describe SearchFlip::Index do
447
447
  it "allows respects class options" do
448
448
  products = create_list(:product, 2)
449
449
 
450
- if ProductIndex.connection.version.to_i >= 5
450
+ if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 5
451
451
  allow(ProductIndex).to receive(:index_options).and_return(routing: "r1")
452
452
 
453
453
  expect { ProductIndex.create products }.to(change { ProductIndex.total_count }.by(2))
@@ -82,7 +82,7 @@ RSpec.describe SearchFlip::Response do
82
82
 
83
83
  ProductIndex.import products
84
84
 
85
- expect(ProductIndex.match_all.results.map(&:id).to_set).to eq(products.map(&:id).to_set)
85
+ expect(ProductIndex.match_all.results.to_set(&:id)).to eq(products.to_set(&:id))
86
86
  end
87
87
  end
88
88
 
@@ -126,7 +126,7 @@ RSpec.describe SearchFlip::Response do
126
126
 
127
127
  response = ProductIndex.match_all.response
128
128
 
129
- expect(response.ids.to_set).to eq(products.map(&:id).map(&:to_s).to_set)
129
+ expect(response.ids.to_set).to eq(products.map(&:id).to_set(&:to_s))
130
130
  expect(response.ids).to eq(response.raw_response["hits"]["hits"].map { |hit| hit["_id"] })
131
131
  end
132
132
  end
data/spec/spec_helper.rb CHANGED
@@ -86,7 +86,7 @@ class CommentIndex
86
86
  include SearchFlip::Index
87
87
 
88
88
  def self.type_name
89
- connection.version.to_i < 8 ? "comments" : "_doc"
89
+ connection.distribution.nil? && connection.version.to_i < 8 ? "comments" : "_doc"
90
90
  end
91
91
 
92
92
  def self.index_name
@@ -113,7 +113,7 @@ class ProductIndex
113
113
  include SearchFlip::Index
114
114
 
115
115
  def self.mapping
116
- if ProductIndex.connection.version.to_i >= 5
116
+ if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 5
117
117
  {
118
118
  properties: {
119
119
  category: {
@@ -136,7 +136,7 @@ class ProductIndex
136
136
  end
137
137
 
138
138
  def self.type_name
139
- connection.version.to_i < 8 ? "products" : "_doc"
139
+ connection.distribution.nil? && connection.version.to_i < 8 ? "products" : "_doc"
140
140
  end
141
141
 
142
142
  def self.index_name
@@ -177,7 +177,7 @@ class TestIndex
177
177
  end
178
178
 
179
179
  def self.type_name
180
- connection.version.to_i < 8 ? "test" : "_doc"
180
+ connection.distribution.nil? && connection.version.to_i < 8 ? "test" : "_doc"
181
181
  end
182
182
 
183
183
  def self.index_name
metadata CHANGED
@@ -1,155 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search_flip
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.2
4
+ version: 3.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Vetter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-27 00:00:00.000000000 Z
11
+ date: 2024-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activerecord
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '3.0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '3.0'
27
- - !ruby/object:Gem::Dependency
28
- name: aws-sdk-core
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: factory_bot
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rspec
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: rubocop
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: sqlite3
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: timecop
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: webmock
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
13
  - !ruby/object:Gem::Dependency
154
14
  name: hashie
155
15
  requirement: !ruby/object:Gem::Requirement
@@ -282,7 +142,10 @@ files:
282
142
  homepage: https://github.com/mrkamel/search_flip
283
143
  licenses:
284
144
  - MIT
285
- metadata: {}
145
+ metadata:
146
+ homepage_uri: https://github.com/mrkamel/search_flip
147
+ source_code_uri: https://github.com/mrkamel/search_flip
148
+ changelog_uri: https://github.com/mrkamel/search_flip/blob/master/CHANGELOG.md
286
149
  post_install_message: |
287
150
  Thanks for using search_flip!
288
151
  When upgrading to 3.x, please check out