zelastic 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/zelastic/config.rb +2 -2
- data/lib/zelastic/index_manager.rb +4 -3
- data/lib/zelastic/indexer.rb +31 -44
- data/lib/zelastic/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f642b0f5988b4f4a0fb9198da0f0276208d3039a
|
4
|
+
data.tar.gz: bb4a08940cf9791cac531be04d7eed6d63ca6fe4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb13a0754667b7de1bb7a78e478beb4740641775bd609a2294063bcbc27186dd835d77ca7789f67dbef0d462b3e204402697ea92714fe9c19be8dab415535de7
|
7
|
+
data.tar.gz: 29ecd1278cca977883c5f2e90ddc4163f674e5064308955ba1363a58fbc7cc56e7f357ce557329422cd6e777d34ae023bac80403f2608dc697b0d3d0549a40de
|
data/Gemfile.lock
CHANGED
data/lib/zelastic/config.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Zelastic
|
4
4
|
class Config
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :clients, :data_source
|
6
6
|
|
7
7
|
def initialize(
|
8
8
|
client:,
|
@@ -11,7 +11,7 @@ module Zelastic
|
|
11
11
|
**overrides,
|
12
12
|
&index_data
|
13
13
|
)
|
14
|
-
@
|
14
|
+
@clients = Array(client)
|
15
15
|
@data_source = data_source
|
16
16
|
@mapping = mapping
|
17
17
|
@index_data = index_data
|
@@ -4,8 +4,9 @@ module Zelastic
|
|
4
4
|
class IndexManager
|
5
5
|
extend Forwardable
|
6
6
|
|
7
|
-
def initialize(config)
|
7
|
+
def initialize(config, client: nil)
|
8
8
|
@config = config
|
9
|
+
@client = client || config.clients.first
|
9
10
|
end
|
10
11
|
|
11
12
|
def create_index(unique_name)
|
@@ -97,8 +98,8 @@ module Zelastic
|
|
97
98
|
|
98
99
|
private
|
99
100
|
|
100
|
-
attr_reader :config
|
101
|
-
def_delegators :config, :
|
101
|
+
attr_reader :config, :client
|
102
|
+
def_delegators :config, :logger
|
102
103
|
|
103
104
|
def indexer
|
104
105
|
@indexer ||= Indexer.new(config)
|
data/lib/zelastic/indexer.rb
CHANGED
@@ -5,8 +5,8 @@ module Zelastic
|
|
5
5
|
class IndexingError < StandardError
|
6
6
|
attr_reader :errors
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@errors =
|
8
|
+
def initialize(result)
|
9
|
+
@errors = result['items'].map { |item| item['error'] }.compact
|
10
10
|
super("Errors indexing: #{errors.join(', ')}")
|
11
11
|
end
|
12
12
|
end
|
@@ -18,65 +18,50 @@ module Zelastic
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def index_batch(batch, index_name: nil)
|
21
|
-
indices = Array(index_name || write_indices)
|
22
21
|
logger.info("ES: Indexing #{config.type} record")
|
23
22
|
|
24
23
|
version = current_version
|
25
|
-
execute_bulk
|
26
|
-
|
27
|
-
|
28
|
-
index_command(index: index, version: version, record: record)
|
29
|
-
end
|
24
|
+
execute_bulk do |index_name|
|
25
|
+
batch.map do |record|
|
26
|
+
index_command(index: index_name, version: version, record: record)
|
30
27
|
end
|
31
|
-
|
28
|
+
end
|
32
29
|
end
|
33
30
|
|
34
31
|
def index_record(record)
|
35
32
|
version = current_version
|
36
33
|
|
37
|
-
execute_bulk
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
)
|
34
|
+
execute_bulk do |index_name|
|
35
|
+
index_command(index: index_name, version: version, record: record)
|
36
|
+
end
|
42
37
|
end
|
43
38
|
|
44
39
|
def delete_by_id(id)
|
45
|
-
|
46
|
-
|
47
|
-
indices.each do |index|
|
48
|
-
client.delete(
|
49
|
-
index: index,
|
50
|
-
type: config.type,
|
51
|
-
id: id
|
52
|
-
)
|
53
|
-
end
|
40
|
+
delete_by_ids([id])
|
54
41
|
end
|
55
42
|
|
56
43
|
def delete_by_ids(ids)
|
57
44
|
logger.info('ES: Deleting batch records')
|
58
45
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
_index: index,
|
67
|
-
_type: config.type,
|
68
|
-
_id: id
|
69
|
-
}
|
46
|
+
execute_bulk do |index_name|
|
47
|
+
ids.map do |id|
|
48
|
+
{
|
49
|
+
delete: {
|
50
|
+
_index: index_name,
|
51
|
+
_type: config.type,
|
52
|
+
_id: id
|
70
53
|
}
|
71
|
-
|
54
|
+
}
|
72
55
|
end
|
73
|
-
|
56
|
+
end
|
74
57
|
end
|
75
58
|
|
76
59
|
def delete_by_query(query)
|
77
60
|
logger.info('ES: Deleting batch records')
|
78
61
|
|
79
|
-
config.
|
62
|
+
config.clients.each do |client|
|
63
|
+
client.delete_by_query(index: config.write_alias, body: { query: query })
|
64
|
+
end
|
80
65
|
end
|
81
66
|
|
82
67
|
private
|
@@ -88,8 +73,8 @@ module Zelastic
|
|
88
73
|
config.data_source.connection.select_one('SELECT txid_current()').fetch('txid_current')
|
89
74
|
end
|
90
75
|
|
91
|
-
def write_indices
|
92
|
-
|
76
|
+
def write_indices(client)
|
77
|
+
client.indices.get_alias(name: config.write_alias).keys
|
93
78
|
end
|
94
79
|
|
95
80
|
def index_command(index:, version:, record:)
|
@@ -105,11 +90,13 @@ module Zelastic
|
|
105
90
|
}
|
106
91
|
end
|
107
92
|
|
108
|
-
def execute_bulk
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
93
|
+
def execute_bulk
|
94
|
+
config.clients.map do |client|
|
95
|
+
commands = write_indices(client).map { |index_name| yield(index) }
|
96
|
+
client.bulk(body: commands).tap do |result|
|
97
|
+
raise IndexingError, result if result['errors']
|
98
|
+
end
|
99
|
+
end
|
113
100
|
end
|
114
101
|
end
|
115
102
|
end
|
data/lib/zelastic/version.rb
CHANGED
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.3.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: 2018-01-
|
11
|
+
date: 2018-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|