zelastic 0.3.0 → 0.3.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
2
  SHA1:
3
- metadata.gz: f642b0f5988b4f4a0fb9198da0f0276208d3039a
4
- data.tar.gz: bb4a08940cf9791cac531be04d7eed6d63ca6fe4
3
+ metadata.gz: 19307349dedf8d7ea1ed2c3bea0f21aaa07ee4ee
4
+ data.tar.gz: c2ffdf1cea48bcc8275d092298dbca72cf97a693
5
5
  SHA512:
6
- metadata.gz: bb13a0754667b7de1bb7a78e478beb4740641775bd609a2294063bcbc27186dd835d77ca7789f67dbef0d462b3e204402697ea92714fe9c19be8dab415535de7
7
- data.tar.gz: 29ecd1278cca977883c5f2e90ddc4163f674e5064308955ba1363a58fbc7cc56e7f357ce557329422cd6e777d34ae023bac80403f2608dc697b0d3d0549a40de
6
+ metadata.gz: 104a24a17ebfe4e227cd4b993b9d3c47c601b70c95c6fe1adc5ed757310e8f8af5eb2b9d40ead0e7eb3fe580d6fb3c0555f42618025ad23145dbbe5b7321dc4e
7
+ data.tar.gz: 2e629f323d6ebc0b9003980348a45754d1a03043a77d1fb92f20a9e67c3673b4cd24fc7076b61ffba772144dc952162e015f763a5a21f2687a9246fc78f591ff
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zelastic (0.3.0)
4
+ zelastic (0.3.1)
5
5
  activesupport
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -48,6 +48,9 @@ You can also override some defaults, if you wish:
48
48
  - `write_alias`: by default this is the `read_alias`, with `_write` appended
49
49
  - `type`: by default this is `read_alias.singularize`
50
50
 
51
+ If you pass an array to as the `client` argument, all writes will be applied to every client in the
52
+ array.
53
+
51
54
  ### Normal usage
52
55
 
53
56
  You'll need to make sure the following gets run whenever an instance of MyModel is updated:
@@ -83,7 +86,7 @@ points at both the old and new indices, so both receive writes. The following st
83
86
  full reindex:
84
87
 
85
88
  1. `new_name = SecureRandom.hex(3)`
86
- 2. `index_manager = Zelastic::IndexManager.new(MyModelIndex)`
89
+ 2. `index_manager = Zelastic::IndexManager.new(MyModelIndex, client: Elasticsearch::Client.new(...))`
87
90
  2. `index_manager.create_index(new_name)`
88
91
  3. `index_manager.populate_index(new_name, batch_size: 3000)`
89
92
  4. Check that the new index is looking alrightish
@@ -92,6 +95,10 @@ full reindex:
92
95
  7. `index_manager.stop_dual_writes`
93
96
  8. `index_manager.cleanup_old_indices`
94
97
 
98
+ The `client` keyword argument to `Zelastic::IndexManager.new` is optional. It defaults to the client
99
+ passed to `Zelastic::Config.new`, if one client is passed, or the first client in the array, if an
100
+ array is passed to `Zelastic::Config.new`.
101
+
95
102
  ## Development
96
103
 
97
104
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -28,7 +28,7 @@ module Zelastic
28
28
  end
29
29
 
30
30
  config.data_source.find_in_batches(batch_size: batch_size) do |batch|
31
- indexer.index_batch(batch, index_name: index_name)
31
+ indexer.index_batch(batch, client: client, index_name: index_name)
32
32
  end
33
33
  end
34
34
 
@@ -17,11 +17,11 @@ module Zelastic
17
17
  @config = config
18
18
  end
19
19
 
20
- def index_batch(batch, index_name: nil)
20
+ def index_batch(batch, client: nil, index_name: nil)
21
21
  logger.info("ES: Indexing #{config.type} record")
22
22
 
23
23
  version = current_version
24
- execute_bulk do |index_name|
24
+ execute_bulk(client: client, index_name: index_name) do |index_name|
25
25
  batch.map do |record|
26
26
  index_command(index: index_name, version: version, record: record)
27
27
  end
@@ -90,9 +90,14 @@ module Zelastic
90
90
  }
91
91
  end
92
92
 
93
- def execute_bulk
93
+ def execute_bulk(client: nil, index_name: nil)
94
+ clients = Array(client || config.clients)
95
+
94
96
  config.clients.map do |client|
95
- commands = write_indices(client).map { |index_name| yield(index) }
97
+ indices = Array(index_name || write_indices(client))
98
+
99
+ commands = indices.map { |index_name| yield(index) }
100
+
96
101
  client.bulk(body: commands).tap do |result|
97
102
  raise IndexingError, result if result['errors']
98
103
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zelastic
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zelastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - carwow Developers