zelastic 0.3.4 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +40 -6
- data/.github/dependabot.yml +9 -0
- data/.rubocop.yml +4 -1
- data/.rubocop_todo.yml +32 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +78 -49
- data/lib/zelastic/config.rb +7 -1
- data/lib/zelastic/index_manager.rb +48 -17
- data/lib/zelastic/indexer.rb +52 -25
- data/lib/zelastic/version.rb +1 -1
- data/zelastic.gemspec +3 -3
- metadata +27 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2f54a69201807f3ba79aa72f7ea5b51c1adfebcdc06d4b51f4662f49c96bc0c7
|
4
|
+
data.tar.gz: '0480ef88c0c3f3f170c18712d2e9208b4fbcd0f7614abbb9cb9b89d2636443be'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ba1d3c04f92728c3a414a3b09551117c664eeb3e1ec9e4f395bb393b33cc8de55bb4239da17fd98be0a8171f3ae038a769f3a2b93147abf42fcac8a13ab0254
|
7
|
+
data.tar.gz: 954fe26c4ed02e57e00ae29c82f26b1eba33f6c637e520db7610a220a851b9d158f4052a9323c506804247b8f527115ce808401cb42c1a893ab93d64f9025a34
|
data/.circleci/config.yml
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
references:
|
2
|
+
ruby: &ruby
|
3
|
+
image: carwow/ruby-ci:2.6
|
4
|
+
environment:
|
5
|
+
ELASTICSEARCH_URL: http://localhost:9200
|
3
6
|
|
4
|
-
elasticsearch_container: &elasticsearch_container
|
5
|
-
|
7
|
+
elasticsearch_container: &elasticsearch_container
|
8
|
+
image: carwow/elasticsearch-ci:5.5.1
|
9
|
+
|
10
|
+
elasticsearch_7_container: &elasticsearch_7_container
|
11
|
+
image: carwow/elasticsearch-ci:7.6.1
|
6
12
|
|
7
13
|
version: 2
|
8
14
|
jobs:
|
@@ -30,7 +36,7 @@ jobs:
|
|
30
36
|
- *ruby
|
31
37
|
steps:
|
32
38
|
- checkout
|
33
|
-
- restore_cache: { keys: ['bundle-{{
|
39
|
+
- restore_cache: { keys: ['bundle-{{ checksum "Gemfile.lock" }}'] }
|
34
40
|
- run: bundle exec rubocop
|
35
41
|
|
36
42
|
tests:
|
@@ -40,9 +46,35 @@ jobs:
|
|
40
46
|
- *elasticsearch_container
|
41
47
|
steps:
|
42
48
|
- checkout
|
43
|
-
- restore_cache: { keys: ['bundle-{{
|
49
|
+
- restore_cache: { keys: ['bundle-{{ checksum "Gemfile.lock" }}'] }
|
50
|
+
- run:
|
51
|
+
name: Wait for ES to be ready
|
52
|
+
command: |
|
53
|
+
until curl $ELASTICSEARCH_URL/_cat/health | egrep '(green|yellow)' 2>&1 > /dev/null; do
|
54
|
+
echo -n .
|
55
|
+
sleep 1
|
56
|
+
done
|
44
57
|
- run: |
|
45
58
|
bundle exec rspec --pattern "**/*_spec.rb" --format "progress"
|
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
|
+
|
46
78
|
workflows:
|
47
79
|
version: 2
|
48
80
|
build:
|
@@ -52,3 +84,5 @@ workflows:
|
|
52
84
|
requires: [bundle]
|
53
85
|
- tests:
|
54
86
|
requires: [bundle]
|
87
|
+
- tests_7:
|
88
|
+
requires: [bundle]
|
data/.rubocop.yml
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
1
3
|
AllCops:
|
2
4
|
TargetRubyVersion: 2.4
|
3
5
|
|
@@ -5,6 +7,7 @@ AllCops:
|
|
5
7
|
Metrics/BlockLength:
|
6
8
|
Exclude:
|
7
9
|
- '*.gemspec'
|
10
|
+
- 'spec/**/*'
|
8
11
|
|
9
12
|
# Configuration parameters: CountComments.
|
10
13
|
Metrics/MethodLength:
|
@@ -18,4 +21,4 @@ Style/Documentation:
|
|
18
21
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
19
22
|
# URISchemes: http, https
|
20
23
|
Metrics/LineLength:
|
21
|
-
Max:
|
24
|
+
Max: 100
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2018-05-27 17:11:31 +0100 using RuboCop version 0.52.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
Lint/ShadowingOuterLocalVariable:
|
11
|
+
Exclude:
|
12
|
+
- 'lib/zelastic/indexer.rb'
|
13
|
+
|
14
|
+
# Offense count: 1
|
15
|
+
Metrics/AbcSize:
|
16
|
+
Max: 17
|
17
|
+
|
18
|
+
# Offense count: 1
|
19
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
20
|
+
Metrics/BlockLength:
|
21
|
+
Max: 83
|
22
|
+
|
23
|
+
# Offense count: 4
|
24
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
25
|
+
# URISchemes: http, https
|
26
|
+
Metrics/LineLength:
|
27
|
+
Max: 146
|
28
|
+
|
29
|
+
# Offense count: 1
|
30
|
+
Naming/AccessorMethodName:
|
31
|
+
Exclude:
|
32
|
+
- 'spec/zelastic/indexer_spec.rb'
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
v0.5.1 - Aug 8th, 2018
|
2
|
+
---
|
3
|
+
|
4
|
+
- Fix re-indexing log output upon initial index creation (#7)
|
5
|
+
|
6
|
+
v0.5.0 - Aug 3rd, 2018
|
7
|
+
---
|
8
|
+
|
9
|
+
- An _ESTIMATED_ % completion of ES re-indexing is logged, as the new index gets populated (#5)
|
10
|
+
|
11
|
+
|
12
|
+
v0.4.0 - May 29th, 2018
|
13
|
+
---
|
14
|
+
|
15
|
+
- Warning rather than exception on ignorable version conflicts (#4)
|
data/Gemfile.lock
CHANGED
@@ -1,66 +1,94 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
zelastic (0.
|
4
|
+
zelastic (0.6.2)
|
5
5
|
activesupport
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (
|
11
|
-
activesupport (=
|
12
|
-
activerecord (
|
13
|
-
activemodel (=
|
14
|
-
activesupport (=
|
15
|
-
|
16
|
-
activesupport (5.1.4)
|
10
|
+
activemodel (6.1.3)
|
11
|
+
activesupport (= 6.1.3)
|
12
|
+
activerecord (6.1.3)
|
13
|
+
activemodel (= 6.1.3)
|
14
|
+
activesupport (= 6.1.3)
|
15
|
+
activesupport (6.1.3)
|
17
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
-
i18n (
|
19
|
-
minitest (
|
20
|
-
tzinfo (~>
|
21
|
-
|
22
|
-
ast (2.
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
i18n (>= 1.6, < 2)
|
18
|
+
minitest (>= 5.1)
|
19
|
+
tzinfo (~> 2.0)
|
20
|
+
zeitwerk (~> 2.3)
|
21
|
+
ast (2.4.1)
|
22
|
+
carwow_rubocop (3.3.0)
|
23
|
+
rubocop (>= 0.78)
|
24
|
+
rubocop-performance
|
25
|
+
rubocop-rspec
|
26
|
+
coderay (1.1.3)
|
27
|
+
concurrent-ruby (1.1.8)
|
28
|
+
diff-lcs (1.4.4)
|
29
|
+
elasticsearch (7.11.2)
|
30
|
+
elasticsearch-api (= 7.11.2)
|
31
|
+
elasticsearch-transport (= 7.11.2)
|
32
|
+
elasticsearch-api (7.11.2)
|
33
|
+
multi_json
|
34
|
+
elasticsearch-transport (7.11.2)
|
35
|
+
faraday (~> 1)
|
36
|
+
multi_json
|
37
|
+
faraday (1.3.0)
|
38
|
+
faraday-net_http (~> 1.0)
|
39
|
+
multipart-post (>= 1.2, < 3)
|
40
|
+
ruby2_keywords
|
41
|
+
faraday-net_http (1.0.1)
|
42
|
+
i18n (1.8.9)
|
27
43
|
concurrent-ruby (~> 1.0)
|
28
|
-
method_source (0.
|
29
|
-
minitest (5.
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
44
|
+
method_source (1.0.0)
|
45
|
+
minitest (5.14.3)
|
46
|
+
multi_json (1.15.0)
|
47
|
+
multipart-post (2.1.1)
|
48
|
+
parallel (1.19.1)
|
49
|
+
parser (2.7.1.3)
|
50
|
+
ast (~> 2.4.0)
|
51
|
+
pry (0.14.0)
|
52
|
+
coderay (~> 1.1)
|
53
|
+
method_source (~> 1.0)
|
37
54
|
rainbow (3.0.0)
|
38
|
-
rake (
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
rspec-
|
43
|
-
|
44
|
-
rspec-
|
45
|
-
rspec-
|
55
|
+
rake (13.0.3)
|
56
|
+
regexp_parser (1.7.1)
|
57
|
+
rexml (3.2.4)
|
58
|
+
rspec (3.10.0)
|
59
|
+
rspec-core (~> 3.10.0)
|
60
|
+
rspec-expectations (~> 3.10.0)
|
61
|
+
rspec-mocks (~> 3.10.0)
|
62
|
+
rspec-core (3.10.0)
|
63
|
+
rspec-support (~> 3.10.0)
|
64
|
+
rspec-expectations (3.10.0)
|
46
65
|
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
-
rspec-support (~> 3.
|
48
|
-
rspec-mocks (3.
|
66
|
+
rspec-support (~> 3.10.0)
|
67
|
+
rspec-mocks (3.10.0)
|
49
68
|
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
-
rspec-support (~> 3.
|
51
|
-
rspec-support (3.
|
52
|
-
rubocop (0.
|
69
|
+
rspec-support (~> 3.10.0)
|
70
|
+
rspec-support (3.10.0)
|
71
|
+
rubocop (0.85.1)
|
53
72
|
parallel (~> 1.10)
|
54
|
-
parser (>= 2.
|
55
|
-
powerpack (~> 0.1)
|
73
|
+
parser (>= 2.7.0.1)
|
56
74
|
rainbow (>= 2.2.2, < 4.0)
|
75
|
+
regexp_parser (>= 1.7)
|
76
|
+
rexml
|
77
|
+
rubocop-ast (>= 0.0.3)
|
57
78
|
ruby-progressbar (~> 1.7)
|
58
|
-
unicode-display_width (
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
79
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
80
|
+
rubocop-ast (0.0.3)
|
81
|
+
parser (>= 2.7.0.1)
|
82
|
+
rubocop-performance (1.6.1)
|
83
|
+
rubocop (>= 0.71.0)
|
84
|
+
rubocop-rspec (1.40.0)
|
85
|
+
rubocop (>= 0.68.1)
|
86
|
+
ruby-progressbar (1.10.1)
|
87
|
+
ruby2_keywords (0.0.4)
|
88
|
+
tzinfo (2.0.4)
|
89
|
+
concurrent-ruby (~> 1.0)
|
90
|
+
unicode-display_width (1.7.0)
|
91
|
+
zeitwerk (2.4.2)
|
64
92
|
|
65
93
|
PLATFORMS
|
66
94
|
ruby
|
@@ -68,11 +96,12 @@ PLATFORMS
|
|
68
96
|
DEPENDENCIES
|
69
97
|
activerecord
|
70
98
|
bundler
|
99
|
+
carwow_rubocop
|
100
|
+
elasticsearch
|
71
101
|
pry
|
72
102
|
rake
|
73
103
|
rspec
|
74
|
-
rubocop
|
75
104
|
zelastic!
|
76
105
|
|
77
106
|
BUNDLED WITH
|
78
|
-
1.
|
107
|
+
2.1.4
|
data/lib/zelastic/config.rb
CHANGED
@@ -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
|
-
|
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)
|
@@ -10,29 +11,21 @@ module Zelastic
|
|
10
11
|
end
|
11
12
|
|
12
13
|
def create_index(unique_name)
|
13
|
-
|
14
|
+
index_name = index_name_from_unique(unique_name)
|
14
15
|
|
15
|
-
client.indices.create(
|
16
|
-
|
17
|
-
body: config.index_definition
|
18
|
-
)
|
19
|
-
|
20
|
-
client.indices.put_alias(index: full_name, name: config.write_alias)
|
16
|
+
client.indices.create(index: index_name, body: config.index_definition)
|
17
|
+
client.indices.put_alias(index: index_name, name: config.write_alias)
|
21
18
|
end
|
22
19
|
|
23
20
|
def populate_index(unique_name = nil, batch_size: 3000)
|
24
|
-
index_name =
|
25
|
-
[config.read_alias, unique_name].join('_')
|
26
|
-
else
|
27
|
-
config.write_alias
|
28
|
-
end
|
21
|
+
index_name = index_name_from_unique(unique_name)
|
29
22
|
|
30
|
-
config.data_source.find_in_batches(batch_size: batch_size) do |batch|
|
23
|
+
config.data_source.find_in_batches(batch_size: batch_size).with_index do |batch, i|
|
24
|
+
logger.info(populate_index_log(batch_size: batch_size, batch_number: i + 1))
|
31
25
|
indexer.index_batch(batch, client: client, index_name: index_name)
|
32
26
|
end
|
33
27
|
end
|
34
28
|
|
35
|
-
# rubocop:disable Metrics/AbcSize
|
36
29
|
def switch_read_index(new_name)
|
37
30
|
new_index = [config.read_alias, new_name].join('_')
|
38
31
|
|
@@ -91,10 +84,11 @@ module Zelastic
|
|
91
84
|
logger.info('Nothing to do: no old indices')
|
92
85
|
return
|
93
86
|
end
|
94
|
-
logger.info(
|
87
|
+
logger.info(
|
88
|
+
"Deleting #{indices_to_delete.count} old indices: #{indices_to_delete.join(', ')}"
|
89
|
+
)
|
95
90
|
client.indices.delete(index: indices_to_delete)
|
96
91
|
end
|
97
|
-
# rubocop:enable Metrics/AbcSize
|
98
92
|
|
99
93
|
private
|
100
94
|
|
@@ -104,5 +98,42 @@ module Zelastic
|
|
104
98
|
def indexer
|
105
99
|
@indexer ||= Indexer.new(config)
|
106
100
|
end
|
101
|
+
|
102
|
+
def index_name_from_unique(unique_name)
|
103
|
+
if unique_name
|
104
|
+
[config.read_alias, unique_name].join('_')
|
105
|
+
else
|
106
|
+
config.write_alias
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def populate_index_log(batch_size:, batch_number:)
|
111
|
+
progress = if current_index_exists?
|
112
|
+
"ESTIMATED: #{indexed_percent(batch_size, batch_number)}%"
|
113
|
+
else
|
114
|
+
'First index'
|
115
|
+
end
|
116
|
+
"ES: (#{progress}) Indexing #{config.type} records"
|
117
|
+
end
|
118
|
+
|
119
|
+
def current_index_size
|
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
|
128
|
+
end
|
129
|
+
|
130
|
+
def indexed_percent(batch_size, batch_number)
|
131
|
+
(batch_size * batch_number.to_f / current_index_size * 100).round(2)
|
132
|
+
end
|
133
|
+
|
134
|
+
def current_index_exists?
|
135
|
+
client.indices.exists?(index: config.read_alias)
|
136
|
+
end
|
107
137
|
end
|
138
|
+
# rubocop:enable Metrics/AbcSize
|
108
139
|
end
|
data/lib/zelastic/indexer.rb
CHANGED
@@ -5,10 +5,8 @@ module Zelastic
|
|
5
5
|
class IndexingError < StandardError
|
6
6
|
attr_reader :errors
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@errors =
|
10
|
-
item['error'] || item.fetch('index', {})['error']
|
11
|
-
end.compact
|
8
|
+
def initialize(errors)
|
9
|
+
@errors = errors
|
12
10
|
super("Errors indexing: #{errors.join(', ')}")
|
13
11
|
end
|
14
12
|
end
|
@@ -19,21 +17,19 @@ module Zelastic
|
|
19
17
|
@config = config
|
20
18
|
end
|
21
19
|
|
22
|
-
def index_batch(batch, client: nil, index_name: nil)
|
23
|
-
logger.info("ES: Indexing #{config.type} record")
|
24
|
-
|
20
|
+
def index_batch(batch, client: nil, index_name: nil, refresh: false)
|
25
21
|
version = current_version
|
26
|
-
execute_bulk(client: client, index_name: index_name) do |
|
22
|
+
execute_bulk(client: client, index_name: index_name, refresh: refresh) do |index|
|
27
23
|
batch.map do |record|
|
28
|
-
index_command(index:
|
24
|
+
index_command(index: index, version: version, record: record)
|
29
25
|
end
|
30
26
|
end
|
31
27
|
end
|
32
28
|
|
33
|
-
def index_record(record)
|
29
|
+
def index_record(record, refresh: false)
|
34
30
|
version = current_version
|
35
31
|
|
36
|
-
execute_bulk do |index_name|
|
32
|
+
execute_bulk(refresh: refresh) do |index_name|
|
37
33
|
[index_command(index: index_name, version: version, record: record)]
|
38
34
|
end
|
39
35
|
end
|
@@ -47,13 +43,10 @@ module Zelastic
|
|
47
43
|
|
48
44
|
execute_bulk do |index_name|
|
49
45
|
ids.map do |id|
|
50
|
-
{
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
_id: id
|
55
|
-
}
|
56
|
-
}
|
46
|
+
delete_params = { _index: index_name, _id: id }
|
47
|
+
delete_params[:_type] = config.type if config.type?
|
48
|
+
|
49
|
+
{ delete: delete_params }
|
57
50
|
end
|
58
51
|
end
|
59
52
|
end
|
@@ -82,19 +75,23 @@ module Zelastic
|
|
82
75
|
end
|
83
76
|
|
84
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
|
+
|
85
85
|
{
|
86
86
|
index: {
|
87
87
|
_index: index,
|
88
|
-
_type: config.type,
|
89
88
|
_id: record.id,
|
90
|
-
_version: version,
|
91
|
-
_version_type: :external,
|
92
89
|
data: config.index_data(record)
|
93
|
-
}
|
90
|
+
}.merge(version_params)
|
94
91
|
}
|
95
92
|
end
|
96
93
|
|
97
|
-
def execute_bulk(client: nil, index_name: nil)
|
94
|
+
def execute_bulk(client: nil, index_name: nil, refresh: false)
|
98
95
|
clients = Array(client || config.clients)
|
99
96
|
|
100
97
|
clients.map do |current_client|
|
@@ -102,10 +99,40 @@ module Zelastic
|
|
102
99
|
|
103
100
|
commands = indices.flat_map { |index| yield(index) }
|
104
101
|
|
105
|
-
current_client.bulk(body: commands).tap do |result|
|
106
|
-
|
102
|
+
current_client.bulk(body: commands, refresh: refresh).tap do |result|
|
103
|
+
check_errors!(result)
|
107
104
|
end
|
108
105
|
end
|
109
106
|
end
|
107
|
+
|
108
|
+
def check_errors!(result)
|
109
|
+
return false unless result['errors']
|
110
|
+
|
111
|
+
errors = result['items']
|
112
|
+
.map { |item| item['error'] || item.fetch('index', {})['error'] }
|
113
|
+
.compact
|
114
|
+
|
115
|
+
ignorable_errors, important_errors = errors
|
116
|
+
.partition { |error| ignorable_error?(error) }
|
117
|
+
|
118
|
+
logger.warn("Ignoring #{ignorable_errors.count} version conflicts") if ignorable_errors.any?
|
119
|
+
|
120
|
+
return unless important_errors.any?
|
121
|
+
|
122
|
+
raise IndexingError, important_errors
|
123
|
+
end
|
124
|
+
|
125
|
+
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
|
+
error['type'] == 'version_conflict_engine_exception' &&
|
135
|
+
error['reason'] =~ regexp
|
136
|
+
end
|
110
137
|
end
|
111
138
|
end
|
data/lib/zelastic/version.rb
CHANGED
data/zelastic.gemspec
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
|
-
lib = File.expand_path('
|
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
|
|
@@ -27,8 +26,9 @@ Gem::Specification.new do |spec|
|
|
27
26
|
|
28
27
|
spec.add_development_dependency 'activerecord'
|
29
28
|
spec.add_development_dependency 'bundler'
|
29
|
+
spec.add_development_dependency 'carwow_rubocop'
|
30
|
+
spec.add_development_dependency 'elasticsearch'
|
30
31
|
spec.add_development_dependency 'pry'
|
31
32
|
spec.add_development_dependency 'rake'
|
32
33
|
spec.add_development_dependency 'rspec'
|
33
|
-
spec.add_development_dependency 'rubocop'
|
34
34
|
end
|
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.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- carwow Developers
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: carwow_rubocop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: elasticsearch
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: pry
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,21 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: rake
|
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: rspec
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - ">="
|
@@ -116,9 +130,12 @@ extensions: []
|
|
116
130
|
extra_rdoc_files: []
|
117
131
|
files:
|
118
132
|
- ".circleci/config.yml"
|
133
|
+
- ".github/dependabot.yml"
|
119
134
|
- ".gitignore"
|
120
135
|
- ".rspec"
|
121
136
|
- ".rubocop.yml"
|
137
|
+
- ".rubocop_todo.yml"
|
138
|
+
- CHANGELOG.md
|
122
139
|
- Gemfile
|
123
140
|
- Gemfile.lock
|
124
141
|
- LICENSE.txt
|
@@ -136,7 +153,7 @@ homepage: https://github.com/carwow/zelastic
|
|
136
153
|
licenses:
|
137
154
|
- MIT
|
138
155
|
metadata: {}
|
139
|
-
post_install_message:
|
156
|
+
post_install_message:
|
140
157
|
rdoc_options: []
|
141
158
|
require_paths:
|
142
159
|
- lib
|
@@ -151,9 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
168
|
- !ruby/object:Gem::Version
|
152
169
|
version: '0'
|
153
170
|
requirements: []
|
154
|
-
|
155
|
-
|
156
|
-
signing_key:
|
171
|
+
rubygems_version: 3.1.4
|
172
|
+
signing_key:
|
157
173
|
specification_version: 4
|
158
174
|
summary: Zero-downtime (re-)indexing of ActiveRecord models into Elasticsearch.
|
159
175
|
test_files: []
|