elastics-client 1.1.0 → 1.1.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.
- data/VERSION +1 -1
- data/lib/elastics-client.rb +2 -0
- data/lib/elastics/api_stubs.rb +2 -1
- data/lib/elastics/configuration.rb +5 -0
- data/lib/elastics/indices.rb +28 -0
- data/lib/elastics/struct/mergeable.rb +38 -0
- data/lib/elastics/tasks.rb +5 -40
- data/lib/tasks.rake +1 -1
- metadata +4 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.1
|
data/lib/elastics-client.rb
CHANGED
@@ -9,6 +9,7 @@ require 'elastics/logger'
|
|
9
9
|
require 'elastics/errors'
|
10
10
|
require 'elastics/utils'
|
11
11
|
|
12
|
+
require 'elastics/struct/mergeable'
|
12
13
|
require 'elastics/struct/prunable'
|
13
14
|
require 'elastics/struct/symbolize'
|
14
15
|
require 'elastics/struct/hash'
|
@@ -41,6 +42,7 @@ require 'elastics/templates'
|
|
41
42
|
|
42
43
|
require 'elastics/http_clients/base'
|
43
44
|
require 'elastics/http_clients/loader'
|
45
|
+
require 'elastics/indices'
|
44
46
|
require 'elastics/configuration'
|
45
47
|
require 'elastics/utility_methods'
|
46
48
|
|
data/lib/elastics/api_stubs.rb
CHANGED
@@ -428,10 +428,11 @@ module Elastics
|
|
428
428
|
# post_index_aliases:
|
429
429
|
# - POST
|
430
430
|
# - /_aliases
|
431
|
+
# - actions: <<actions>>
|
431
432
|
#
|
432
433
|
#
|
433
434
|
# Usage:
|
434
|
-
# Elastics.post_index_aliases
|
435
|
+
# Elastics.post_index_aliases :actions => actions
|
435
436
|
#
|
436
437
|
def Elastics.post_index_aliases(*vars)
|
437
438
|
## this is a stub, used for reference
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Elastics
|
2
|
+
class Indices < Hash
|
3
|
+
|
4
|
+
extend Struct::Mergeable
|
5
|
+
|
6
|
+
def initialize(config_path)
|
7
|
+
hash = YAML.load(Utils.erb_process(config_path))
|
8
|
+
replace Utils.delete_allcaps_keys(hash)
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_index(index, name=nil, opts={})
|
12
|
+
name ||= index
|
13
|
+
Elastics.PUT name, self[index], opts
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_indices(indices=keys, opts={})
|
17
|
+
indices.each{|i| create_index(i, i, opts)}
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete_indices(indices=keys, opts={})
|
21
|
+
indices.each do |i|
|
22
|
+
args = {:index=>i}.merge(opts)
|
23
|
+
Elastics.delete_index(args)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Elastics
|
2
|
+
module Struct
|
3
|
+
# allows deep merge between Hashes
|
4
|
+
module Mergeable
|
5
|
+
|
6
|
+
def deep_merge(*hashes)
|
7
|
+
merged = deep_dup
|
8
|
+
hashes.each {|h2| merged.replace(deep_merge_hash(merged,h2))}
|
9
|
+
merged
|
10
|
+
end
|
11
|
+
|
12
|
+
def deep_merge!(*hashes)
|
13
|
+
replace deep_merge(*hashes)
|
14
|
+
end
|
15
|
+
|
16
|
+
def deep_dup
|
17
|
+
Marshal.load(Marshal.dump(self))
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def deep_merge_hash(h1, h2)
|
23
|
+
h2 ||= {}
|
24
|
+
h1.merge(h2) do |key, oldval, newval|
|
25
|
+
case
|
26
|
+
when oldval.is_a?(::Hash) && newval.is_a?(::Hash)
|
27
|
+
deep_merge_hash(oldval, newval)
|
28
|
+
when oldval.is_a?(::Array) && newval.is_a?(::Array)
|
29
|
+
oldval + newval
|
30
|
+
else
|
31
|
+
newval
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/elastics/tasks.rb
CHANGED
@@ -10,53 +10,18 @@ module Elastics
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def default_options
|
13
|
-
@default_options ||= { :force
|
14
|
-
:index
|
15
|
-
:config_file => Conf.config_file }
|
13
|
+
@default_options ||= { :force => false,
|
14
|
+
:index => Conf.indices.keys }
|
16
15
|
end
|
17
16
|
|
18
17
|
def create_indices
|
19
|
-
indices.
|
20
|
-
|
21
|
-
raise ExistingIndexError, "#{index.inspect} already exists. Please use FORCE=1 if you want to delete it first." \
|
22
|
-
if exist?(index)
|
23
|
-
create(index)
|
24
|
-
end
|
18
|
+
Conf.indices.delete_indices(options[:index]) if options[:force]
|
19
|
+
Conf.indices.create_indices(options[:index])
|
25
20
|
end
|
26
21
|
|
27
22
|
def delete_indices
|
28
|
-
indices.
|
29
|
-
end
|
30
|
-
|
31
|
-
def config_hash
|
32
|
-
@config_hash ||= ( hash = YAML.load(Utils.erb_process(config_path))
|
33
|
-
Utils.delete_allcaps_keys(hash) )
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def indices
|
39
|
-
i = options[:index] || config_hash.keys
|
40
|
-
i.is_a?(Array) ? i : [i]
|
41
|
-
end
|
42
|
-
|
43
|
-
def exist?(index)
|
44
|
-
Elastics.exist?(:index => index)
|
45
|
-
end
|
46
|
-
|
47
|
-
def config_path
|
48
|
-
@config_path ||= options[:config_file] || Conf.config_file
|
49
|
-
end
|
50
|
-
|
51
|
-
def delete_index(index)
|
52
|
-
Elastics.delete_index(:index => index) if exist?(index)
|
53
|
-
end
|
54
|
-
|
55
|
-
def create(index)
|
56
|
-
config_hash[index] = {} unless config_hash.has_key?(index)
|
57
|
-
Elastics.POST "/#{index}", config_hash[index]
|
23
|
+
Conf.indices.delete_indices(options[:index])
|
58
24
|
end
|
59
25
|
|
60
26
|
end
|
61
|
-
|
62
27
|
end
|
data/lib/tasks.rake
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastics-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- lib/elastics/http_clients/loader.rb
|
104
104
|
- lib/elastics/http_clients/patron.rb
|
105
105
|
- lib/elastics/http_clients/rest_client.rb
|
106
|
+
- lib/elastics/indices.rb
|
106
107
|
- lib/elastics/logger.rb
|
107
108
|
- lib/elastics/prog_bar.rb
|
108
109
|
- lib/elastics/result.rb
|
@@ -112,6 +113,7 @@ files:
|
|
112
113
|
- lib/elastics/result/search.rb
|
113
114
|
- lib/elastics/struct/array.rb
|
114
115
|
- lib/elastics/struct/hash.rb
|
116
|
+
- lib/elastics/struct/mergeable.rb
|
115
117
|
- lib/elastics/struct/paginable.rb
|
116
118
|
- lib/elastics/struct/prunable.rb
|
117
119
|
- lib/elastics/struct/symbolize.rb
|