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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +8 -1
- data/lib/zelastic/index_manager.rb +1 -1
- data/lib/zelastic/indexer.rb +9 -4
- data/lib/zelastic/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19307349dedf8d7ea1ed2c3bea0f21aaa07ee4ee
|
4
|
+
data.tar.gz: c2ffdf1cea48bcc8275d092298dbca72cf97a693
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 104a24a17ebfe4e227cd4b993b9d3c47c601b70c95c6fe1adc5ed757310e8f8af5eb2b9d40ead0e7eb3fe580d6fb3c0555f42618025ad23145dbbe5b7321dc4e
|
7
|
+
data.tar.gz: 2e629f323d6ebc0b9003980348a45754d1a03043a77d1fb92f20a9e67c3673b4cd24fc7076b61ffba772144dc952162e015f763a5a21f2687a9246fc78f591ff
|
data/Gemfile.lock
CHANGED
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.
|
data/lib/zelastic/indexer.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/zelastic/version.rb
CHANGED