elastic-util 0.1.1 → 0.1.2
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/bin/elastic-util +3 -0
- data/lib/elastic_util.rb +13 -2
- 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: 65b4319be21549be3a86ed896834f464f1d36542
|
4
|
+
data.tar.gz: 40d05eb1c8f6db2d98b5606f14ab5fe26eda6a2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72cfa5a35d7746aeea475972a132966b120ea9571a3176d218d5c138a13a6661085900856b02ec41a1b10dc7f886c136f4d274d5e2c4e40c33258c8539379b40
|
7
|
+
data.tar.gz: 96da3e80ab3dfa74f214e6d5d27cd7ec5e3b0b2523faa664ec3894a4eea631d8d2bd005d7ef398f72f0aef09afc20395ba1ae61f52352b520f92085ff5182e1d
|
data/bin/elastic-util
CHANGED
@@ -20,6 +20,9 @@ when "backup"
|
|
20
20
|
opts.on('--exclude-indices x,y,z', Array, "The indices to exclude from backup. Default is none.") do |val|
|
21
21
|
options[:exclude_indices] = val.collect {|it| it.strip }
|
22
22
|
end
|
23
|
+
opts.on('--exclude-fields x,y,z', Array, "The fields to exclude from backup. Default is '_id'.") do |val|
|
24
|
+
options[:exclude_fields] = val.collect {|it| it.strip }
|
25
|
+
end
|
23
26
|
opts.on( '-s', '--size NUMBER', "The size api parameter. This dicates the size of the files and api payloads. Default is 1000." ) do |val|
|
24
27
|
options[:size] = val.to_i
|
25
28
|
end
|
data/lib/elastic_util.rb
CHANGED
@@ -12,7 +12,7 @@ require 'fileutils'
|
|
12
12
|
#
|
13
13
|
module ElasticUtil
|
14
14
|
|
15
|
-
VERSION = "0.1.
|
15
|
+
VERSION = "0.1.2"
|
16
16
|
|
17
17
|
# The name of the data directory, relative to the user provided backup directory.
|
18
18
|
DUMP_DIR = "es_data"
|
@@ -42,6 +42,7 @@ module ElasticUtil
|
|
42
42
|
# @param [Hash] opts The options for this backup.
|
43
43
|
# @option opts [Array] :indices The indices to backup. Default is all.
|
44
44
|
# @option opts [Array] :exclude_indices Exclude certain indexes.
|
45
|
+
# @option opts [Array] :exclude_fields Exclude certain fields. Default is ['_id'].
|
45
46
|
# @option opts [String] :scroll The scroll api parameter, Default is '5m'.
|
46
47
|
# @option opts [Integer] :size The size api parameter. Default is 1000.
|
47
48
|
# @option opts [true] :force Delete existing backup directory instead of erroring. Default is false.
|
@@ -93,6 +94,11 @@ module ElasticUtil
|
|
93
94
|
opts[:scroll] ||= '5m'
|
94
95
|
opts[:size] ||= 1000
|
95
96
|
|
97
|
+
# exclude _id by default.
|
98
|
+
if !opts.key?(:exclude_fields)
|
99
|
+
opts[:exclude_fields] = ['_id']
|
100
|
+
end
|
101
|
+
|
96
102
|
# validate backup path
|
97
103
|
if File.exists?(path)
|
98
104
|
if opts[:force]
|
@@ -220,7 +226,7 @@ module ElasticUtil
|
|
220
226
|
return true
|
221
227
|
end
|
222
228
|
|
223
|
-
def self.save_bulk_data(path, hits, file_index=nil) # :nodoc:
|
229
|
+
def self.save_bulk_data(path, hits, file_index=nil, opts={}) # :nodoc:
|
224
230
|
if hits && !hits.empty?
|
225
231
|
hits.each do |hit|
|
226
232
|
index_name = hit['_index']
|
@@ -233,6 +239,11 @@ module ElasticUtil
|
|
233
239
|
'_index' => hit['_index'], '_type' => hit['_type'], '_id' => hit['_id']
|
234
240
|
} }
|
235
241
|
source_json = hit['_source']
|
242
|
+
if opts[:exclude_fields] && source_json
|
243
|
+
opts[:exclude_fields].each do |field|
|
244
|
+
source_json.delete(field)
|
245
|
+
end
|
246
|
+
end
|
236
247
|
File.open(file_name, 'a') do |file|
|
237
248
|
file.write JSON.generate(action_json) + "\n" + JSON.generate(source_json) + "\n"
|
238
249
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic-util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Dickson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|