zelastic 0.7.0 → 0.8.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: 82591810835538bb7b3ede975d3731fc2b3300dfa9934f72f81ed323458c8145
4
- data.tar.gz: c7631b4cb764dbfffdf4efd35296b9b9c5d5ce790c03464c7ba584ad060cae47
3
+ metadata.gz: 7b45ad7dd15f213cc571c3da4f021ff80129dcccb375ae98aedde7b22b759b05
4
+ data.tar.gz: '08328c62f6485a0b11300dc9c651ca3e8c99179c84ea2c3f5235a921ca676d9a'
5
5
  SHA512:
6
- metadata.gz: 43647ec72340be7b8a4121eb7190d74844ad3284f38457dbe6948ddd81d4ed46fe9c2c7b9b8ae057db07b506efb5c2e7393f5eba43e209ecbf49dd58ec22b70c
7
- data.tar.gz: 1b834cba1e6bffd46e108528b3d0eac68ca3766b86c5a28741db3c838b71d9c509cd1e42ac6dd82ff5f9ed7fc99a7cf1534507fc48b3fd1b388980ebbf0b33cd
6
+ metadata.gz: a3e38047bf9f47bc8e7353f8e52387a7bd6722e291f96291d09a50257cd28a43cf7fba2abcd9681abb3797aa5acce67f38b09cabb6ecbaf8e4638b2a7e6e21b6
7
+ data.tar.gz: 94572581d7fa5f6c6de6485cacd9232a310418379f981d12d0523183f6922f5bcbbeb290605e4452ccb51603f702aa5bf52a9540ed681002a1b2e389a2dff670
data/.circleci/config.yml CHANGED
@@ -14,6 +14,7 @@ jobs:
14
14
  - image: "elasticsearch:<< parameters.elasticsearch_version >>"
15
15
  environment:
16
16
  "discovery.type": single-node
17
+ "xpack.security.enabled": false
17
18
  environment:
18
19
  ELASTICSEARCH_GEM_VERSION: "<< parameters.elasticsearch_gem_version >>"
19
20
  steps:
@@ -28,20 +29,20 @@ workflows:
28
29
  test:
29
30
  jobs:
30
31
  - test:
31
- name: "test with elasticsearch v7
32
+ name: "test with elasticsearch v8
32
33
  and gem << matrix.elasticsearch_gem_version >>
33
34
  and ruby v<< matrix.ruby_version >>"
34
- elasticsearch_version: "7.17.5"
35
+ elasticsearch_version: "8.3.3"
35
36
  matrix:
36
37
  parameters:
37
38
  ruby_version: ["3.1", "2.7"]
38
- elasticsearch_gem_version: ["~> 7", "~> 5"]
39
+ elasticsearch_gem_version: ["~> 8", "~> 7"]
39
40
  - test:
40
- name: "test with elasticsearch v5
41
- and gem ~> 5
41
+ name: "test with elasticsearch v7
42
+ and gem << matrix.elasticsearch_gem_version >>
42
43
  and ruby v<< matrix.ruby_version >>"
43
- elasticsearch_version: "5.6-alpine"
44
- elasticsearch_gem_version: "~> 5"
44
+ elasticsearch_version: "7.17.5"
45
45
  matrix:
46
46
  parameters:
47
47
  ruby_version: ["3.1", "2.7"]
48
+ elasticsearch_gem_version: ["~> 7"]
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /log/*.log
9
10
  /Gemfile.lock
10
11
 
11
12
  # rspec failure tracking
data/.rubocop.yml CHANGED
@@ -8,3 +8,6 @@ inherit_mode:
8
8
 
9
9
  Metrics:
10
10
  Enabled: false
11
+
12
+ Gemspec/RequireMFA:
13
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,15 +1,47 @@
1
- v0.5.1 - Aug 8th, 2018
2
- ---
1
+ # Changelog
3
2
 
4
- - Fix re-indexing log output upon initial index creation (#7)
3
+ All notable changes to this project will be documented in this file.
5
4
 
6
- v0.5.0 - Aug 3rd, 2018
7
- ---
5
+ The format is based on [Keep a Changelog],
6
+ and this project adheres to [Semantic Versioning].
8
7
 
9
- - An _ESTIMATED_ % completion of ES re-indexing is logged, as the new index gets populated (#5)
8
+ [Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
9
+ [Semantic Versioning]: https://semver.org/spec/v2.0.0.html
10
10
 
11
+ ## How do I make a good changelog?
11
12
 
12
- v0.4.0 - May 29th, 2018
13
- ---
13
+ ### Guiding Principles
14
14
 
15
- - Warning rather than exception on ignorable version conflicts (#4)
15
+ - Changelogs are for humans, not machines.
16
+ - There should be an entry for every single version.
17
+ - The same types of changes should be grouped.
18
+ - Versions and sections should be linkable.
19
+ - The latest version comes first.
20
+ - The release date of each version is displayed.
21
+ - Keep an `Unreleased` section at the top to track upcoming changes.
22
+
23
+ ### Types of changes
24
+
25
+ - `Added` for new features.
26
+ - `Changed` for changes in existing functionality.
27
+ - `Deprecated` for soon-to-be removed features.
28
+ - `Removed` for now removed features.
29
+ - `Fixed` for any bug fixes.
30
+ - `Security` in case of vulnerabilities.
31
+
32
+ ## [Unreleased] - XXXX-XX-XX
33
+
34
+ ## [0.8.0] - 2022-08-19
35
+ ### Added
36
+ - Support for Ruby 3 (and keep support for 2.7).
37
+ - Support for Elasticsearch v8 (and keep support for v7).
38
+ - Support setting a logger in `Config`.
39
+ - Support refresh on `IndexManager#populate_index`.
40
+ - Support Proc in `Config#data_source` so it can be lazily evaluated.
41
+
42
+ ### Removed
43
+ - Drop support for Ruby 2.6.
44
+ - Drop support for Elasticsearch v5 and v6.
45
+
46
+ [Unreleased]: https://github.com/carwow/zelastic/compare/v0.8.0...HEAD
47
+ [0.8.0]: https://github.com/carwow/zelastic/releases/tag/v0.8.0
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
- # Zero-downtime indexing from ActiveRecord->Elasticsearch
1
+ # Zelastic
2
+
3
+ Zero-downtime Elasticsearch tooling for managing indices and indexing from
4
+ ActiveRecord with PostgreSQL to Elasticsearch.
2
5
 
3
6
  ## Installation
4
7
 
@@ -10,13 +13,14 @@ gem 'zelastic'
10
13
 
11
14
  And then execute:
12
15
 
13
- $ bundle
16
+ $ bundle install
14
17
 
15
18
  Or install it yourself as:
16
19
 
17
20
  $ gem install zelastic
18
21
 
19
22
  ## Usage
23
+
20
24
  ### Setup
21
25
 
22
26
  For each ActiveRecord scope you want to index, you'll need a configuration:
@@ -46,7 +50,6 @@ You can also override some defaults, if you wish:
46
50
  here
47
51
  - `read_alias`: by default this is the table name of the `data_source`
48
52
  - `write_alias`: by default this is the `read_alias`, with `_write` appended
49
- - `type`: by default this is `read_alias.singularize`
50
53
 
51
54
  If you pass an array to as the `client` argument, all writes will be applied to every client in the
52
55
  array.
@@ -2,31 +2,36 @@
2
2
 
3
3
  module Zelastic
4
4
  class Config
5
- attr_reader :clients, :data_source
5
+ attr_reader :clients
6
6
 
7
7
  def initialize(
8
8
  client:,
9
9
  data_source:,
10
10
  mapping:,
11
+ logger: nil,
11
12
  **overrides,
12
13
  &index_data
13
14
  )
14
15
  @clients = Array(client)
15
16
  @data_source = data_source
16
17
  @mapping = mapping
17
- @index_data = index_data
18
- @_type = overrides.fetch(:type, true)
18
+ @logger = logger
19
19
  @overrides = overrides
20
- end
21
-
22
- def type?
23
- @_type
20
+ @index_data = index_data
24
21
  end
25
22
 
26
23
  def index_data(model)
27
24
  @index_data.call(model)
28
25
  end
29
26
 
27
+ def data_source
28
+ if @data_source.respond_to? :call
29
+ @data_source.call
30
+ else
31
+ @data_source
32
+ end
33
+ end
34
+
30
35
  def read_alias
31
36
  @read_alias ||= overrides.fetch(:read_alias) { data_source.table_name }
32
37
  end
@@ -35,10 +40,6 @@ module Zelastic
35
40
  @write_alias ||= overrides.fetch(:write_alias) { [read_alias, 'write'].join('_') }
36
41
  end
37
42
 
38
- def type
39
- @type ||= overrides.fetch(:type, read_alias.singularize)
40
- end
41
-
42
43
  def logger
43
44
  return Rails.logger if defined?(Rails)
44
45
 
@@ -48,7 +49,7 @@ module Zelastic
48
49
  def index_definition
49
50
  {
50
51
  settings: overrides.fetch(:index_settings, {}),
51
- mappings: type ? { type => mapping } : mapping
52
+ mappings: mapping
52
53
  }
53
54
  end
54
55
 
@@ -16,12 +16,12 @@ module Zelastic
16
16
  client.indices.put_alias(index: index_name, name: config.write_alias)
17
17
  end
18
18
 
19
- def populate_index(unique_name = nil, batch_size: 3000)
19
+ def populate_index(unique_name = nil, batch_size: 3000, refresh: false)
20
20
  index_name = index_name_from_unique(unique_name)
21
21
 
22
22
  config.data_source.find_in_batches(batch_size: batch_size).with_index do |batch, i|
23
23
  logger.info(populate_index_log(batch_size: batch_size, batch_number: i + 1))
24
- indexer.index_batch(batch, client: client, index_name: index_name)
24
+ indexer.index_batch(batch, client: client, index_name: index_name, refresh: refresh)
25
25
  end
26
26
  end
27
27
 
@@ -116,18 +116,11 @@ module Zelastic
116
116
  else
117
117
  'First index'
118
118
  end
119
- "ES: (#{progress}) Indexing #{config.type} records"
119
+ "ES: (#{progress}) Indexing records"
120
120
  end
121
121
 
122
122
  def current_index_size
123
- @current_index_size ||= client.count(**count_params)['count']
124
- end
125
-
126
- def count_params
127
- {
128
- index: config.read_alias,
129
- type: config.type? ? config.type : nil
130
- }.compact
123
+ @current_index_size ||= client.count(index: config.read_alias)['count']
131
124
  end
132
125
 
133
126
  def indexed_percent(batch_size, batch_number)
@@ -43,10 +43,7 @@ module Zelastic
43
43
 
44
44
  execute_bulk do |index_name|
45
45
  ids.map do |id|
46
- delete_params = { _index: index_name, _id: id }
47
- delete_params[:_type] = config.type if config.type?
48
-
49
- { delete: delete_params }
46
+ { delete: { _index: index_name, _id: id } }
50
47
  end
51
48
  end
52
49
  end
@@ -76,19 +73,14 @@ module Zelastic
76
73
  end
77
74
 
78
75
  def index_command(index:, version:, record:)
79
- version_params =
80
- if config.type?
81
- { _version: version, _version_type: :external, _type: config.type }
82
- else
83
- { version: version, version_type: :external }
84
- end
85
-
86
76
  {
87
77
  index: {
88
78
  _index: index,
89
79
  _id: record.id,
90
- data: config.index_data(record)
91
- }.merge(version_params)
80
+ data: config.index_data(record),
81
+ version: version,
82
+ version_type: :external
83
+ }
92
84
  }
93
85
  end
94
86
 
@@ -123,16 +115,11 @@ module Zelastic
123
115
  end
124
116
 
125
117
  def ignorable_error?(error)
126
- # rubocop:disable Layout/LineLength
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
133
- # rubocop:enable Layout/LineLength
134
118
  error['type'] == 'version_conflict_engine_exception' &&
135
- error['reason'] =~ regexp
119
+ error['reason'] =~ VERSION_CONFLICT_ERROR_REGEXP
136
120
  end
121
+
122
+ VERSION_CONFLICT_ERROR_REGEXP =
123
+ /^\[\d+\]: version conflict, current version \[\d+\] is higher or equal to the one provided \[\d+\]$/.freeze
137
124
  end
138
125
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zelastic
4
- VERSION = '0.7.0'
4
+ VERSION = '0.8.0'
5
5
  end
data/log/.keep ADDED
File without changes
data/zelastic.gemspec CHANGED
@@ -22,12 +22,13 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
+ spec.add_dependency 'elasticsearch', '>= 7', '< 9'
26
+
27
+ spec.add_dependency 'activerecord'
25
28
  spec.add_dependency 'activesupport'
26
29
 
27
- spec.add_development_dependency 'activerecord'
28
30
  spec.add_development_dependency 'bundler', '~> 2'
29
31
  spec.add_development_dependency 'carwow_rubocop', '~> 4'
30
- spec.add_development_dependency 'elasticsearch', '>= 5', '< 8'
31
32
  spec.add_development_dependency 'pry', '~> 0.14'
32
33
  spec.add_development_dependency 'rake', '~> 13'
33
34
  spec.add_development_dependency 'rspec', '~> 3'
metadata CHANGED
@@ -1,17 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zelastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - carwow Developers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-16 00:00:00.000000000 Z
11
+ date: 2022-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activesupport
14
+ name: elasticsearch
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '7'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '9'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '7'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '9'
33
+ - !ruby/object:Gem::Dependency
34
+ name: activerecord
15
35
  requirement: !ruby/object:Gem::Requirement
16
36
  requirements:
17
37
  - - ">="
@@ -25,13 +45,13 @@ dependencies:
25
45
  - !ruby/object:Gem::Version
26
46
  version: '0'
27
47
  - !ruby/object:Gem::Dependency
28
- name: activerecord
48
+ name: activesupport
29
49
  requirement: !ruby/object:Gem::Requirement
30
50
  requirements:
31
51
  - - ">="
32
52
  - !ruby/object:Gem::Version
33
53
  version: '0'
34
- type: :development
54
+ type: :runtime
35
55
  prerelease: false
36
56
  version_requirements: !ruby/object:Gem::Requirement
37
57
  requirements:
@@ -66,26 +86,6 @@ dependencies:
66
86
  - - "~>"
67
87
  - !ruby/object:Gem::Version
68
88
  version: '4'
69
- - !ruby/object:Gem::Dependency
70
- name: elasticsearch
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '5'
76
- - - "<"
77
- - !ruby/object:Gem::Version
78
- version: '8'
79
- type: :development
80
- prerelease: false
81
- version_requirements: !ruby/object:Gem::Requirement
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- version: '5'
86
- - - "<"
87
- - !ruby/object:Gem::Version
88
- version: '8'
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: pry
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -154,6 +154,7 @@ files:
154
154
  - lib/zelastic/index_manager.rb
155
155
  - lib/zelastic/indexer.rb
156
156
  - lib/zelastic/version.rb
157
+ - log/.keep
157
158
  - zelastic.gemspec
158
159
  homepage: https://github.com/carwow/zelastic
159
160
  licenses: