es_dump_restore 2.0.0 → 2.1.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: 4fd3daa61667baf72f9f0c62fe8b6f71e0e5c5de
4
- data.tar.gz: a9d1eb03b685529be48895e92a856443e8cec280
3
+ metadata.gz: 6484c47c7bc3f4b8d77671791b34471f0a2767d5
4
+ data.tar.gz: 70e2b1056a94d7a5168d930ce2d190ebaa4b618b
5
5
  SHA512:
6
- metadata.gz: 2a5728d62cfd999870e6d19b3ba4ad8350dce18d8ec860616c39d475cd01d39f27bf85fa429e4da75f6c2fb5d7c6d339c6a89289cc0a808f2aeaf67bc4d6e5d3
7
- data.tar.gz: 6076595aba9cb8c3beec6259fd70fef81917ea8841115c7fb1c76e2e858c531b25f06d92fb0d785cf582c89095629e0387adaae34a63c6e5ef3591bd26b82c28
6
+ metadata.gz: 48279c3090efc690a1df0c1f3eaac017890b4e0dbe8992314aff007b57f2b1438dbdddbfe78d6c2332d57ec2e8ca89780c200f4183b6bcf9f8b1286ff9b4e78c
7
+ data.tar.gz: 1a06773b02e7b7677a3b6eb4417900c723861481b9620d04e79936dbbb8957ff625f55cf923af679d49ed1774b350cbdd4a6b73deaf31853da6c7ee96e13dd27
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # Version 2.1.0 - September 30, 2015
2
+
3
+ * Dump index metadata along with data
4
+ * Bugfix: correctly retrieve \_settings when using the dump_type action
5
+
1
6
  # Version 2.0.0 - July 1, 2015
2
7
 
3
8
  Thanks to Alex Tomlins for this feature contribution
@@ -16,51 +16,13 @@ module EsDumpRestore
16
16
  desc "dump URL INDEX_NAME FILENAME", "Creates a dumpfile based on the given ElasticSearch index"
17
17
  def dump(url, index_name, filename)
18
18
  client = EsClient.new(url, index_name, nil)
19
-
20
- Dumpfile.write(filename) do |dumpfile|
21
- dumpfile.index = {
22
- settings: client.settings,
23
- mappings: client.mappings
24
- }
25
-
26
- client.start_scan do |scroll_id, total|
27
- dumpfile.num_objects = total
28
- bar = ProgressBar.new(total) if options[:progressbar]
29
-
30
- dumpfile.get_objects_output_stream do |out|
31
- client.each_scroll_hit(scroll_id) do |hit|
32
- metadata = { index: { _type: hit["_type"], _id: hit["_id"] } }
33
- out.write("#{MultiJson.dump(metadata)}\n#{MultiJson.dump(hit["_source"])}\n")
34
- bar.increment! if options[:progressbar]
35
- end
36
- end
37
- end
38
- end
19
+ _dump(client, filename)
39
20
  end
40
21
 
41
22
  desc "dump_type URL INDEX_NAME TYPE FILENAME", "Creates a dumpfile based on the given ElasticSearch index"
42
23
  def dump_type(url, index_name, type, filename)
43
24
  client = EsClient.new(url, index_name, type)
44
-
45
- Dumpfile.write(filename) do |dumpfile|
46
- dumpfile.index = {
47
- settings: client.settings,
48
- mappings: client.mappings
49
- }
50
-
51
- client.start_scan do |scroll_id, total|
52
- dumpfile.num_objects = total
53
- bar = ProgressBar.new(total) if options[:progressbar]
54
-
55
- dumpfile.get_objects_output_stream do |out|
56
- client.each_scroll_hit(scroll_id) do |hit|
57
- metadata = { index: { _type: hit["_type"], _id: hit["_id"] } }
58
- out.write("#{MultiJson.dump(metadata)}\n#{MultiJson.dump(hit["_source"])}\n")
59
- bar.increment! if options[:progressbar]
60
- end
61
- end
62
- end
63
- end
25
+ _dump(client, filename)
64
26
  end
65
27
 
66
28
  desc "restore URL INDEX_NAME FILENAME", "Restores a dumpfile into the given ElasticSearch index"
@@ -97,5 +59,35 @@ module EsDumpRestore
97
59
  client.replace_alias_and_close_old_index alias_name
98
60
  end
99
61
 
62
+ private
63
+
64
+ def _dump(client, filename)
65
+ Dumpfile.write(filename) do |dumpfile|
66
+ dumpfile.index = {
67
+ settings: client.settings,
68
+ mappings: client.mappings
69
+ }
70
+
71
+ client.start_scan do |scroll_id, total|
72
+ dumpfile.num_objects = total
73
+ bar = ProgressBar.new(total) if options[:progressbar]
74
+
75
+ dumpfile.get_objects_output_stream do |out|
76
+ client.each_scroll_hit(scroll_id) do |hit|
77
+ hit['fields'] ||= {}
78
+ metadata = { index: { _type: hit["_type"], _id: hit["_id"] } }
79
+
80
+ %w(_timestamp _version _routing _percolate _parent _ttl).each do |metadata_field|
81
+ metadata[:index][metadata_field] = hit['fields'][metadata_field] if hit['fields'][metadata_field]
82
+ end
83
+
84
+ out.write("#{MultiJson.dump(metadata)}\n#{MultiJson.dump(hit["_source"])}\n")
85
+
86
+ bar.increment! if options[:progressbar]
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
100
92
  end
101
93
  end
@@ -29,7 +29,7 @@ module EsDumpRestore
29
29
  end
30
30
 
31
31
  def settings
32
- data = request(:get, "#{@path_prefix}/_settings")
32
+ data = request(:get, "#{@index_name}/_settings")
33
33
  if data.values.size != 1
34
34
  raise "Unexpected response: #{data}"
35
35
  end
@@ -44,7 +44,10 @@ module EsDumpRestore
44
44
  def start_scan(&block)
45
45
  scroll = request(:get, "#{@path_prefix}/_search",
46
46
  query: { search_type: 'scan', scroll: '10m', size: 500 },
47
- body: MultiJson.dump({ query: { match_all: {} } }) )
47
+ body: MultiJson.dump({
48
+ fields: ['_source', '_timestamp', '_version', '_routing', '_percolate', '_parent', '_ttl'],
49
+ query: { match_all: {} } }
50
+ ))
48
51
  total = scroll["hits"]["total"]
49
52
  scroll_id = scroll["_scroll_id"]
50
53
 
@@ -1,3 +1,3 @@
1
1
  module EsDumpRestore
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: es_dump_restore
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nat Budin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-01 00:00:00.000000000 Z
11
+ date: 2015-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json