elastic-util 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/elastic-util +3 -0
  3. data/lib/elastic_util.rb +13 -2
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1605712be564451df792a694f30b74bf78befa6b
4
- data.tar.gz: 804fc6fe444d9624dbebe7610428baeeb6f80d13
3
+ metadata.gz: 65b4319be21549be3a86ed896834f464f1d36542
4
+ data.tar.gz: 40d05eb1c8f6db2d98b5606f14ab5fe26eda6a2d
5
5
  SHA512:
6
- metadata.gz: a86df992ead1805df8ad5faccb5ed1b6e7f898ed14ce79b5a8f8be37ca79a4cb14fb0691f1df900800cf0d4bd5c446eccbdb3172f60b1b3f3aba57c166cbf26b
7
- data.tar.gz: 80179b4b84e18b2f899d5be506b0e81d2c47dbcdddc6b631c23df118c9bcbcb6d757e33047e26927e071a7a4c4ece760f1c2422f99acbc98d844997508c713de
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.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.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-02-27 00:00:00.000000000 Z
11
+ date: 2018-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler