zelastic 0.5.1 → 0.6.1

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
- SHA1:
3
- metadata.gz: 7688ccc666c5845c29e20e163691a19f35ee368d
4
- data.tar.gz: 6de7dbb95705106006706f62d03425345d7509c1
2
+ SHA256:
3
+ metadata.gz: 118f50ebd50d4291a03b2274b4129a9d69e15aee8b744ce986524ab3a7496845
4
+ data.tar.gz: ef294b31041ecf9a0cdae04008950eb76fd2e19c60058db234b19549dd646ea6
5
5
  SHA512:
6
- metadata.gz: 113fedb974cb28813e3b8084dbec4dd154b2821afcd0127cbef7b6874b0438b5986fa336bdcc2159502f0869d9f2455ce836907821026393e0814a6e36350456
7
- data.tar.gz: 8af284f5e38267416325426ea8a72ad62a485698ee51e2e66790bac8590e9e3e6a61c1b85671e31bf0ec35c3d63a9dbbc8c3017abb28ef6d655021b666140975
6
+ metadata.gz: d22f6e8c566c3e400ab3d02e3a4fe6f6aa114ac00533ca42848058a297e2593450f3cefebb19206d21acaf5d62da74f08ad247be137af07404e9bdc388faf900
7
+ data.tar.gz: 7e369fe3a13e13289e98ee18e1b55cd83c0034a85ab3e0282a4ab70c302b05b41cbb7a329a69261880285e437f42e654ad332e2143f08babda5efbc5f54e1208
@@ -7,6 +7,9 @@ references:
7
7
  elasticsearch_container: &elasticsearch_container
8
8
  image: carwow/elasticsearch-ci:5.5.1
9
9
 
10
+ elasticsearch_7_container: &elasticsearch_7_container
11
+ image: carwow/elasticsearch-ci:7.6.1
12
+
10
13
  version: 2
11
14
  jobs:
12
15
  bundle:
@@ -54,6 +57,24 @@ jobs:
54
57
  - run: |
55
58
  bundle exec rspec --pattern "**/*_spec.rb" --format "progress"
56
59
 
60
+ tests_7:
61
+ working_directory: ~/zelastic
62
+ docker:
63
+ - *ruby
64
+ - *elasticsearch_7_container
65
+ steps:
66
+ - checkout
67
+ - restore_cache: { keys: ['bundle-{{ checksum "Gemfile.lock" }}'] }
68
+ - run:
69
+ name: Wait for ES to be ready
70
+ command: |
71
+ until curl $ELASTICSEARCH_URL/_cat/health | egrep '(green|yellow)' 2>&1 > /dev/null; do
72
+ echo -n .
73
+ sleep 1
74
+ done
75
+ - run: |
76
+ bundle exec rspec --pattern "**/*_spec.rb" --format "progress"
77
+
57
78
  workflows:
58
79
  version: 2
59
80
  build:
@@ -63,3 +84,5 @@ workflows:
63
84
  requires: [bundle]
64
85
  - tests:
65
86
  requires: [bundle]
87
+ - tests_7:
88
+ requires: [bundle]
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zelastic (0.5.1)
4
+ zelastic (0.6.0)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -47,7 +47,7 @@ GEM
47
47
  coderay (~> 1.1.0)
48
48
  method_source (~> 0.9.0)
49
49
  rainbow (3.0.0)
50
- rake (12.3.0)
50
+ rake (13.0.1)
51
51
  rspec (3.7.0)
52
52
  rspec-core (~> 3.7.0)
53
53
  rspec-expectations (~> 3.7.0)
@@ -88,4 +88,4 @@ DEPENDENCIES
88
88
  zelastic!
89
89
 
90
90
  BUNDLED WITH
91
- 1.16.2
91
+ 1.17.2
@@ -15,9 +15,14 @@ module Zelastic
15
15
  @data_source = data_source
16
16
  @mapping = mapping
17
17
  @index_data = index_data
18
+ @_type = overrides.fetch(:type, true)
18
19
  @overrides = overrides
19
20
  end
20
21
 
22
+ def type?
23
+ @_type
24
+ end
25
+
21
26
  def index_data(model)
22
27
  @index_data.call(model)
23
28
  end
@@ -36,13 +41,14 @@ module Zelastic
36
41
 
37
42
  def logger
38
43
  return Rails.logger if defined?(Rails)
44
+
39
45
  @logger ||= Logger.new(STDOUT)
40
46
  end
41
47
 
42
48
  def index_definition
43
49
  {
44
50
  settings: overrides.fetch(:index_settings, {}),
45
- mappings: { type => mapping }
51
+ mappings: type ? { type => mapping } : mapping
46
52
  }
47
53
  end
48
54
 
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zelastic
4
- class IndexManager
4
+ # rubocop:disable Metrics/AbcSize
5
+ class IndexManager # rubocop:disable Metrics/ClassLength
5
6
  extend Forwardable
6
7
 
7
8
  def initialize(config, client: nil)
@@ -25,7 +26,6 @@ module Zelastic
25
26
  end
26
27
  end
27
28
 
28
- # rubocop:disable Metrics/AbcSize
29
29
  def switch_read_index(new_name)
30
30
  new_index = [config.read_alias, new_name].join('_')
31
31
 
@@ -89,7 +89,6 @@ module Zelastic
89
89
  )
90
90
  client.indices.delete(index: indices_to_delete)
91
91
  end
92
- # rubocop:enable Metrics/AbcSize
93
92
 
94
93
  private
95
94
 
@@ -118,7 +117,14 @@ module Zelastic
118
117
  end
119
118
 
120
119
  def current_index_size
121
- @current_index_size ||= client.count(index: config.read_alias, type: config.type)['count']
120
+ @current_index_size ||= client.count(**count_params)['count']
121
+ end
122
+
123
+ def count_params
124
+ {
125
+ index: config.read_alias,
126
+ type: config.type? ? config.type : nil
127
+ }.compact
122
128
  end
123
129
 
124
130
  def indexed_percent(batch_size, batch_number)
@@ -129,4 +135,5 @@ module Zelastic
129
135
  client.indices.exists?(index: config.read_alias)
130
136
  end
131
137
  end
138
+ # rubocop:enable Metrics/AbcSize
132
139
  end
@@ -43,13 +43,10 @@ module Zelastic
43
43
 
44
44
  execute_bulk do |index_name|
45
45
  ids.map do |id|
46
- {
47
- delete: {
48
- _index: index_name,
49
- _type: config.type,
50
- _id: id
51
- }
52
- }
46
+ delete_params = { _index: index_name, _id: id }
47
+ delete_params[:_type] = config.type if config.type?
48
+
49
+ { delete: delete_params }
53
50
  end
54
51
  end
55
52
  end
@@ -78,15 +75,19 @@ module Zelastic
78
75
  end
79
76
 
80
77
  def index_command(index:, version:, record:)
78
+ version_params =
79
+ if config.type?
80
+ { _version: version, _version_type: :external, _type: config.type }
81
+ else
82
+ { version: version, version_type: :external }
83
+ end
84
+
81
85
  {
82
86
  index: {
83
87
  _index: index,
84
- _type: config.type,
85
88
  _id: record.id,
86
- _version: version,
87
- _version_type: :external,
88
89
  data: config.index_data(record)
89
- }
90
+ }.merge(version_params)
90
91
  }
91
92
  end
92
93
 
@@ -117,12 +118,18 @@ module Zelastic
117
118
  logger.warn("Ignoring #{ignorable_errors.count} version conflicts") if ignorable_errors.any?
118
119
 
119
120
  return unless important_errors.any?
121
+
120
122
  raise IndexingError, important_errors
121
123
  end
122
124
 
123
125
  def ignorable_error?(error)
124
126
  # rubocop:disable Metrics/LineLength
125
- regexp = /^\[#{config.type}\]\[\d+\]: version conflict, current version \[\d+\] is higher or equal to the one provided \[\d+\]$/
127
+ regexp =
128
+ if config.type?
129
+ /^\[#{config.type}\]\[\d+\]: version conflict, current version \[\d+\] is higher or equal to the one provided \[\d+\]$/
130
+ else
131
+ /^\[\d+\]: version conflict, current version \[\d+\] is higher or equal to the one provided \[\d+\]$/
132
+ end
126
133
  # rubocop:enable Metrics/LineLength
127
134
  error['type'] == 'version_conflict_engine_exception' &&
128
135
  error['reason'] =~ regexp
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zelastic
4
- VERSION = '0.5.1'
4
+ VERSION = '0.6.1'
5
5
  end
@@ -1,7 +1,6 @@
1
-
2
1
  # frozen_string_literal: true
3
2
 
4
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
5
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
5
  require 'zelastic/version'
7
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zelastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - carwow Developers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-08 00:00:00.000000000 Z
11
+ date: 2020-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -167,8 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0'
169
169
  requirements: []
170
- rubyforge_project:
171
- rubygems_version: 2.6.14.1
170
+ rubygems_version: 3.0.3
172
171
  signing_key:
173
172
  specification_version: 4
174
173
  summary: Zero-downtime (re-)indexing of ActiveRecord models into Elasticsearch.