metacrunch-elasticsearch 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -4
- data/lib/metacrunch/elasticsearch/cli/dump_metadata.rb +84 -0
- data/lib/metacrunch/elasticsearch/cli/list_indices.rb +19 -0
- data/lib/metacrunch/elasticsearch/cli.rb +59 -0
- data/lib/metacrunch/elasticsearch/index_creator.rb +4 -2
- data/lib/metacrunch/elasticsearch/version.rb +1 -1
- data/lib/metacrunch/elasticsearch.rb +1 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26718380b20c6d344d4f356604d8800711f721a4
|
4
|
+
data.tar.gz: e4e38880f4709aebb74c76332d2e18f95fd0a2ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9662ded772976b51e221caf81938795a91da1dcb0b66c939143480ebad25b2292e5ccf657a9e86e52c77b9fe2444e0910f9e2f591d62aba2927714718efd0a2c
|
7
|
+
data.tar.gz: d7007c5911b76fbc3815fdff41a4b3aa8e55efe190d114b304ce46527986b8123e936e8a34d6f37a9e4ac2b2ca4062f8a272f5c4dd801bdae796d229953ca686
|
data/Gemfile
CHANGED
@@ -13,11 +13,10 @@ group :development do
|
|
13
13
|
|
14
14
|
if !ENV["CI"]
|
15
15
|
gem "hashdiff"
|
16
|
-
gem "pry", "~> 0.
|
17
|
-
gem "pry-byebug", "
|
16
|
+
gem "pry", "~> 0.10.3"
|
17
|
+
gem "pry-byebug", "~> 3.3.0"
|
18
18
|
gem "pry-rescue", "~> 1.4.2"
|
19
|
-
gem "pry-
|
20
|
-
gem "pry-syntax-hacks", "~> 0.0.6"
|
19
|
+
gem "pry-state", "~> 0.1.7"
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require "elasticsearch"
|
2
|
+
require_relative "../cli"
|
3
|
+
|
4
|
+
class Metacrunch::Elasticsearch::Cli::DumpMetadata < Metacrunch::Command
|
5
|
+
def call
|
6
|
+
[:mappings, :settings].each do |_element|
|
7
|
+
_filename_option = "#{_element}_filename"
|
8
|
+
|
9
|
+
if options[_filename_option].present?
|
10
|
+
options["dump_#{_element}"] = true
|
11
|
+
end
|
12
|
+
|
13
|
+
if options[_filename_option] == _filename_option
|
14
|
+
options.delete(_filename_option)
|
15
|
+
end
|
16
|
+
|
17
|
+
if options["dump_#{_element}"]
|
18
|
+
if filename = options["#{_element}_filename"]
|
19
|
+
File.write(filename, format(send(_element), format_from_filename(filename)))
|
20
|
+
else
|
21
|
+
puts send(_element)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
if !options[:dump_mapping] && !options[:dump_settings]
|
27
|
+
puts format(settings.merge(mappings), options[:format])
|
28
|
+
|
29
|
+
if options[:format] == :yaml
|
30
|
+
$stderr.puts <<-MESSAGE.strip_heredoc
|
31
|
+
|
32
|
+
You have requested to dump settings and mapping into YAML. Please keep in mind
|
33
|
+
that if you are trying to create an index with both, settings and mapping, this
|
34
|
+
request has to be JSON formatted. Nevertheless you can create the index with YAML
|
35
|
+
settings and put a YAML formatted mapping afterwards.
|
36
|
+
|
37
|
+
https://github.com/elastic/elasticsearch/issues/1755
|
38
|
+
|
39
|
+
MESSAGE
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
alias_method :perform, :call
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def client
|
48
|
+
@client ||= Elasticsearch::Client.new(url: options[:url])
|
49
|
+
end
|
50
|
+
|
51
|
+
def format(obj, format)
|
52
|
+
if format.to_sym == :json
|
53
|
+
JSON.pretty_generate(obj)
|
54
|
+
elsif format.to_sym == :yaml
|
55
|
+
YAML.dump(obj)
|
56
|
+
else
|
57
|
+
raise "Unknown output format!"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def format_from_filename(filename)
|
62
|
+
return nil if filename.blank?
|
63
|
+
|
64
|
+
case File.extname(filename)
|
65
|
+
when /json\Z/i then :json
|
66
|
+
when /yml\Z|yaml\Z/i then :yaml
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def mappings
|
71
|
+
client.indices.get_mapping(index: @options[:index], type: @options[:type]).try(:values).try(:first)
|
72
|
+
end
|
73
|
+
|
74
|
+
def settings
|
75
|
+
client.indices.get_settings(index: @options[:index])
|
76
|
+
.try(:values)
|
77
|
+
.try(:first)
|
78
|
+
.try(:tap) do |_obj|
|
79
|
+
_obj["settings"]["index"].reject! do |_key, _|
|
80
|
+
["creation_date", "uuid", "version"].include?(_key)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "elasticsearch"
|
2
|
+
require_relative "../cli"
|
3
|
+
|
4
|
+
class Metacrunch::Elasticsearch::Cli::ListIndices < Metacrunch::Command
|
5
|
+
def call
|
6
|
+
puts indices
|
7
|
+
end
|
8
|
+
alias_method :perform, :call
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def client
|
13
|
+
@client ||= Elasticsearch::Client.new(url: @options[:url])
|
14
|
+
end
|
15
|
+
|
16
|
+
def indices
|
17
|
+
client.cat.indices(h: "index", format: :json).map { |_element| _element["index"] }
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Metacrunch
|
2
|
+
module Elasticsearch
|
3
|
+
module Cli
|
4
|
+
require_relative "./cli/dump_metadata"
|
5
|
+
require_relative "./cli/list_indices"
|
6
|
+
#require_relative "./cli/reindex_command"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
Metacrunch::Cli.setup("elasticsearch", "Commands for Elasticsearch") do |r|
|
12
|
+
#
|
13
|
+
#
|
14
|
+
#
|
15
|
+
r.register(Metacrunch::Elasticsearch::Cli::DumpMetadata) do |c|
|
16
|
+
c.name "dump_metadata"
|
17
|
+
c.usage "dump_metadata"
|
18
|
+
c.desc "Dump index metadata"
|
19
|
+
|
20
|
+
c.option :url,
|
21
|
+
desc: "Elasticsearch url",
|
22
|
+
type: :string,
|
23
|
+
aliases: "-u",
|
24
|
+
required: true
|
25
|
+
c.option :format,
|
26
|
+
desc: "Output format",
|
27
|
+
type: :string,
|
28
|
+
aliases: "-f",
|
29
|
+
default: :yaml
|
30
|
+
c.option :mappings_filename,
|
31
|
+
desc: "Dump mappings",
|
32
|
+
aliases: "-m"
|
33
|
+
c.option :settings_filename,
|
34
|
+
desc: "Dump settings",
|
35
|
+
aliases: "-s",
|
36
|
+
default: false
|
37
|
+
c.option :index,
|
38
|
+
desc: "Index name",
|
39
|
+
aliases: "-i",
|
40
|
+
required: true
|
41
|
+
c.option :type,
|
42
|
+
desc: "Type to dump mapping for",
|
43
|
+
aliases: "-t",
|
44
|
+
default: "_default_"
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
r.register(Metacrunch::Elasticsearch::Cli::ListIndices) do |c|
|
49
|
+
c.name "list_indices"
|
50
|
+
c.usage "list_indices"
|
51
|
+
c.desc "List indices"
|
52
|
+
|
53
|
+
c.option :url,
|
54
|
+
desc: "Elasticsearch url",
|
55
|
+
type: :string,
|
56
|
+
aliases: "-u",
|
57
|
+
required: true
|
58
|
+
end
|
59
|
+
end
|
@@ -11,10 +11,11 @@ class Metacrunch::Elasticsearch::IndexCreator < Metacrunch::Processor
|
|
11
11
|
attr_accessor :default_mapping
|
12
12
|
attr_accessor :delete_existing_index
|
13
13
|
attr_accessor :logger
|
14
|
+
attr_accessor :settings
|
14
15
|
|
15
16
|
def initialize(options = {})
|
16
17
|
(@client_args = options).deep_symbolize_keys!
|
17
|
-
extract_options!(@client_args, :_client_options_, :default_mapping, :delete_existing_index, :logger, :number_of_shards, :number_of_replicas)
|
18
|
+
extract_options!(@client_args, :_client_options_, :default_mapping, :delete_existing_index, :logger, :number_of_shards, :number_of_replicas, :settings)
|
18
19
|
raise ArgumentError.new("You have to supply an index name!") if @client_args[:index].blank?
|
19
20
|
end
|
20
21
|
|
@@ -37,7 +38,8 @@ class Metacrunch::Elasticsearch::IndexCreator < Metacrunch::Processor
|
|
37
38
|
{
|
38
39
|
body: {
|
39
40
|
number_of_shards: @number_of_shards,
|
40
|
-
number_of_replicas: @number_of_replicas
|
41
|
+
number_of_replicas: @number_of_replicas,
|
42
|
+
settings: @settings
|
41
43
|
}.compact
|
42
44
|
}
|
43
45
|
))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metacrunch-elasticsearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- René Sprotte
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-01-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -69,6 +69,9 @@ files:
|
|
69
69
|
- bin/console
|
70
70
|
- bin/setup
|
71
71
|
- lib/metacrunch/elasticsearch.rb
|
72
|
+
- lib/metacrunch/elasticsearch/cli.rb
|
73
|
+
- lib/metacrunch/elasticsearch/cli/dump_metadata.rb
|
74
|
+
- lib/metacrunch/elasticsearch/cli/list_indices.rb
|
72
75
|
- lib/metacrunch/elasticsearch/client_factory.rb
|
73
76
|
- lib/metacrunch/elasticsearch/index_creator.rb
|
74
77
|
- lib/metacrunch/elasticsearch/indexer.rb
|
@@ -100,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
103
|
version: '0'
|
101
104
|
requirements: []
|
102
105
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.
|
106
|
+
rubygems_version: 2.5.1
|
104
107
|
signing_key:
|
105
108
|
specification_version: 4
|
106
109
|
summary: Metacrunch elasticsearch package
|