zelastic 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05b9d19442778ad53fe696cbcf6d202b9216cd53
4
- data.tar.gz: 3e8e17c98cc6ee0332449e232c7de492dc94f79e
3
+ metadata.gz: 04e31f09152172933b5800dfd711a673e6d22c6c
4
+ data.tar.gz: d943d84ef9ee7770c4597b4853f75cfd83ec9ab1
5
5
  SHA512:
6
- metadata.gz: a7186c7a3dd66d97bc7567e33023742c2fda9718846d8e58c2bbe9c17ef18055858e7e5fb0b600d3629b365c300350e6b694068368a40599ccaf9be41c931d74
7
- data.tar.gz: bd24900db1022ef69a0a457c03f50e3e2a1ec884e4eba60ddd2084a3555ba0e9921a99b39293dacc1436ebcf441de40eab8184f4269229c93127990dbe2a46e2
6
+ metadata.gz: c81a965e8b108be4ff1b4cacdee26fceb6a2164af583e93b06bd9d1919aa9bffb5d29a39220d01c26d0b41f6f0f60da6dffefa6e23b47d4a54edc748344b861e
7
+ data.tar.gz: f5ce82aac1b74cbac4526c36bdecf4694b39fc7ac2b1f234298fc635aa883e51f22552954963383b785f15558f27c2e1307d34359c2e5c620ecb34ea300a46ea
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ v0.5.0 - Aug 3rd, 2018
2
+ ---
3
+
4
+ - An _ESTIMATED_ % completion of ES re-indexing is logged, as the new index gets populated (#5)
5
+
6
+
1
7
  v0.4.0 - May 29th, 2018
2
8
  ---
3
9
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zelastic (0.4.0)
4
+ zelastic (0.5.0)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -10,24 +10,23 @@ module Zelastic
10
10
  end
11
11
 
12
12
  def create_index(unique_name)
13
- full_name = [config.read_alias, unique_name].join('_')
13
+ index_name = index_name_from_unique(unique_name)
14
14
 
15
15
  client.indices.create(
16
- index: full_name,
16
+ index: index_name,
17
17
  body: config.index_definition
18
18
  )
19
19
 
20
- client.indices.put_alias(index: full_name, name: config.write_alias)
20
+ client.indices.put_alias(index: index_name, name: config.write_alias)
21
21
  end
22
22
 
23
23
  def populate_index(unique_name = nil, batch_size: 3000)
24
- index_name = if unique_name
25
- [config.read_alias, unique_name].join('_')
26
- else
27
- config.write_alias
28
- end
24
+ index_name = index_name_from_unique(unique_name)
29
25
 
30
- config.data_source.find_in_batches(batch_size: batch_size) do |batch|
26
+ config.data_source.find_in_batches(batch_size: batch_size).with_index do |batch, i|
27
+ logger.info(
28
+ "ES: (ESTIMATED: #{indexed_percent(batch_size, i + 1)}%) Indexing #{config.type} records"
29
+ )
31
30
  indexer.index_batch(batch, client: client, index_name: index_name)
32
31
  end
33
32
  end
@@ -106,5 +105,21 @@ module Zelastic
106
105
  def indexer
107
106
  @indexer ||= Indexer.new(config)
108
107
  end
108
+
109
+ def index_name_from_unique(unique_name)
110
+ if unique_name
111
+ [config.read_alias, unique_name].join('_')
112
+ else
113
+ config.write_alias
114
+ end
115
+ end
116
+
117
+ def current_index_size
118
+ @current_index_size ||= client.count(index: config.read_alias, type: config.type)['count']
119
+ end
120
+
121
+ def indexed_percent(batch_size, batch_number)
122
+ (batch_size * batch_number.to_f / current_index_size * 100).round(2)
123
+ end
109
124
  end
110
125
  end
@@ -18,12 +18,10 @@ module Zelastic
18
18
  end
19
19
 
20
20
  def index_batch(batch, client: nil, index_name: nil)
21
- logger.info("ES: Indexing #{config.type} record")
22
-
23
21
  version = current_version
24
- execute_bulk(client: client, index_name: index_name) do |index_name|
22
+ execute_bulk(client: client, index_name: index_name) do |index|
25
23
  batch.map do |record|
26
- index_command(index: index_name, version: version, record: record)
24
+ index_command(index: index, version: version, record: record)
27
25
  end
28
26
  end
29
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zelastic
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  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.0
4
+ version: 0.5.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-05-29 00:00:00.000000000 Z
11
+ date: 2018-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport