es_dump_restore 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -2
- data/lib/es_dump_restore/app.rb +26 -1
- data/lib/es_dump_restore/es_client.rb +3 -2
- data/lib/es_dump_restore/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -15,11 +15,15 @@ series of commands to be sent to the ElasticSearch bulk API.
|
|
15
15
|
|
16
16
|
To dump an ElasticSearch index to a file:
|
17
17
|
|
18
|
-
es_dump_restore dump ELASTIC_SEARCH_SERVER_URL INDEX_NAME
|
18
|
+
es_dump_restore dump ELASTIC_SEARCH_SERVER_URL INDEX_NAME DESTINATION_FILE_ZIP
|
19
|
+
|
20
|
+
To dump an ElasticSearch index by type to a file:
|
21
|
+
|
22
|
+
es_dump_restore dump ELASTIC_SEARCH_SERVER_URL INDEX_NAME TYPE DESTINATION_FILE_ZIP
|
19
23
|
|
20
24
|
To restore an index to an ElasticSearch server:
|
21
25
|
|
22
|
-
es_dump_restore restore ELASTIC_SEARCH_SERVER_URL DESTINATON_INDEX
|
26
|
+
es_dump_restore restore ELASTIC_SEARCH_SERVER_URL DESTINATON_INDEX FILENAME_ZIP
|
23
27
|
|
24
28
|
## Contributing
|
25
29
|
|
data/lib/es_dump_restore/app.rb
CHANGED
@@ -9,7 +9,32 @@ module EsDumpRestore
|
|
9
9
|
|
10
10
|
desc "dump URL INDEX_NAME FILENAME", "Creates a dumpfile based on the given ElasticSearch index"
|
11
11
|
def dump(url, index_name, filename)
|
12
|
-
client = EsClient.new(url, index_name)
|
12
|
+
client = EsClient.new(url, index_name, nil)
|
13
|
+
|
14
|
+
Dumpfile.write(filename) do |dumpfile|
|
15
|
+
dumpfile.index = {
|
16
|
+
settings: client.settings,
|
17
|
+
mappings: client.mappings
|
18
|
+
}
|
19
|
+
|
20
|
+
client.start_scan do |scroll_id, total|
|
21
|
+
dumpfile.num_objects = total
|
22
|
+
bar = ProgressBar.new(total)
|
23
|
+
|
24
|
+
dumpfile.get_objects_output_stream do |out|
|
25
|
+
client.each_scroll_hit(scroll_id) do |hit|
|
26
|
+
metadata = { index: { _type: hit["_type"], _id: hit["_id"] } }
|
27
|
+
out.write("#{MultiJson.dump(metadata)}\n#{MultiJson.dump(hit["_source"])}\n")
|
28
|
+
bar.increment!
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "dump_type URL INDEX_NAME TYPE FILENAME", "Creates a dumpfile based on the given ElasticSearch index"
|
36
|
+
def dump_type(url, index_name, type, filename)
|
37
|
+
client = EsClient.new(url, index_name, type)
|
13
38
|
|
14
39
|
Dumpfile.write(filename) do |dumpfile|
|
15
40
|
dumpfile.index = {
|
@@ -7,10 +7,11 @@ module EsDumpRestore
|
|
7
7
|
attr_accessor :base_uri
|
8
8
|
attr_accessor :index_name
|
9
9
|
|
10
|
-
def initialize(base_uri, index_name)
|
10
|
+
def initialize(base_uri, index_name, type)
|
11
11
|
@httpclient = HTTPClient.new
|
12
12
|
@index_name = index_name
|
13
|
-
|
13
|
+
|
14
|
+
@base_uri = type.nil? ? URI.parse(base_uri + "/" + index_name + "/") : URI.parse(base_uri + "/" + index_name + "/" + type + "/")
|
14
15
|
end
|
15
16
|
|
16
17
|
def mappings
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: es_dump_restore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nat Budin
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
version_requirements: !ruby/object:Gem::Requirement
|