ej 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ej/commands.rb +29 -9
- data/lib/ej/core.rb +12 -3
- data/lib/ej/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c287ef1568268d6329315195b6f2255a6cca268
|
4
|
+
data.tar.gz: d700cae1c877b2009112ec5125ba615f66444bb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bfeb51bc5202b6185a168e1c38b4a705248f01357191ef8bc2198b1b8f3d6b715762d8ac367b8d72ba397cf2e894c3a51183f37b8ebdbc06dda77b9ecce646d
|
7
|
+
data.tar.gz: 41009a197052df5f4b0030e14f970a2964d70c79e8157f0d62b5e6fb760009d35dc2ebdbe1123bfdc0b05e0079f6d4b27c80ea27cf3c6b21cb6e3bbbca297a63
|
data/lib/ej/commands.rb
CHANGED
@@ -16,7 +16,7 @@ module Ej
|
|
16
16
|
map '-s' => :search
|
17
17
|
map '-f' => :facet
|
18
18
|
map '-c' => :count
|
19
|
-
map '-
|
19
|
+
map '-b' => :bulk
|
20
20
|
map '-l' => :indices
|
21
21
|
map '-a' => :aliases
|
22
22
|
map '-m' => :mapping
|
@@ -34,14 +34,24 @@ module Ej
|
|
34
34
|
option :type, type: :string, aliases: '-t', default: nil, desc: 'type'
|
35
35
|
option :size, type: :numeric, aliases: '-n', default: nil, desc: 'size'
|
36
36
|
option :from, type: :numeric, aliases: '--from', default: 0, desc: 'from'
|
37
|
+
option :fields, type: :array, aliases: '--fields', default: nil, desc: 'fields'
|
37
38
|
option :source_only, type: :boolean, aliases: '--so', default: true, desc: 'from'
|
38
|
-
|
39
|
-
|
39
|
+
option :query, type: :string, aliases: '-q', default: nil, desc: 'query'
|
40
|
+
def search(query = options['query'])
|
41
|
+
puts_json(@core.search(options['type'],
|
42
|
+
query,
|
43
|
+
options['size'],
|
44
|
+
options['from'],
|
45
|
+
options['source_only'],
|
46
|
+
query,
|
47
|
+
options['fields']
|
48
|
+
))
|
40
49
|
end
|
41
50
|
|
42
51
|
desc 'total [lucene query]', 'total'
|
43
52
|
option :type, type: :string, aliases: '-t', default: nil, desc: 'type'
|
44
|
-
|
53
|
+
option :query, type: :string, aliases: '-q', default: nil, desc: 'query'
|
54
|
+
def count(query = options['query'])
|
45
55
|
puts_json(@core.search(options['type'], query, 0, 0, false))
|
46
56
|
end
|
47
57
|
|
@@ -52,15 +62,15 @@ module Ej
|
|
52
62
|
puts_json(@core.distinct(term, options['type'], options['query']))
|
53
63
|
end
|
54
64
|
|
55
|
-
desc '
|
65
|
+
desc 'copy', 'copy index'
|
56
66
|
option :source, type: :string, aliases: '--source', required: true, desc: 'source host'
|
57
67
|
option :dest, type: :string, aliases: '--dest', required: true, desc: 'dest host'
|
58
68
|
option :query, type: :string, aliases: '-q', default: nil, desc: 'query'
|
59
|
-
def
|
60
|
-
@core.
|
69
|
+
def copy
|
70
|
+
@core.copy(options['source'], options['dest'], options['query'])
|
61
71
|
end
|
62
72
|
|
63
|
-
desc 'dump', '
|
73
|
+
desc 'dump', 'dump index'
|
64
74
|
option :query, type: :string, aliases: '-q', default: nil, desc: 'query'
|
65
75
|
def dump
|
66
76
|
@core.dump(options['query'])
|
@@ -92,7 +102,7 @@ module Ej
|
|
92
102
|
puts_json(@core.max(options['term']))
|
93
103
|
end
|
94
104
|
|
95
|
-
desc '-
|
105
|
+
desc '-b', 'bulk import STDIN JSON'
|
96
106
|
option :index, aliases: '-i', type: :string, default: "logstash-#{Time.now.strftime('%Y.%m.%d')}", required: true, desc: 'index'
|
97
107
|
option :type, type: :string, aliases: '-t', default: nil, required: true, desc: 'type'
|
98
108
|
option :timestamp_key, aliases: '--timestamp_key', type: :string, desc: 'timestamp key', default: nil
|
@@ -200,6 +210,16 @@ module Ej
|
|
200
210
|
puts_json(@core.refresh)
|
201
211
|
end
|
202
212
|
|
213
|
+
desc 'info', 'view nodes info'
|
214
|
+
def nodes_info
|
215
|
+
puts_json @core.nodes_info
|
216
|
+
end
|
217
|
+
|
218
|
+
desc 'stats', 'view nodes stats'
|
219
|
+
def nodes_stats
|
220
|
+
puts_json @core.nodes_stats
|
221
|
+
end
|
222
|
+
|
203
223
|
desc '--j2h', 'json to hash'
|
204
224
|
def json_to_hash
|
205
225
|
pp Yajl::Parser.parse(STDIN.read)
|
data/lib/ej/core.rb
CHANGED
@@ -15,12 +15,13 @@ module Ej
|
|
15
15
|
@client = Elasticsearch::Client.new hosts: host, logger: @logger, index: @index
|
16
16
|
end
|
17
17
|
|
18
|
-
def search(type, query, size, from, source_only, routing = nil)
|
18
|
+
def search(type, query, size, from, source_only, routing = nil, fields = nil)
|
19
19
|
body = { from: from }
|
20
20
|
body[:size] = size unless size.nil?
|
21
21
|
body[:query] = { query_string: { query: query } } unless query.nil?
|
22
22
|
search_option = { index: @index, type: type, body: body }
|
23
23
|
search_option[:routing] = routing unless routing.nil?
|
24
|
+
search_option[:_source] = fields.nil? ? nil : fields.join(',')
|
24
25
|
results = Hashie::Mash.new(@client.search(search_option))
|
25
26
|
source_only ? get_sources(results) : results
|
26
27
|
end
|
@@ -31,7 +32,7 @@ module Ej
|
|
31
32
|
@client.search index: @index, type: type, body: body
|
32
33
|
end
|
33
34
|
|
34
|
-
def
|
35
|
+
def copy(source, dest, query)
|
35
36
|
per = DEFAULT_PER
|
36
37
|
num = 0
|
37
38
|
logger = Logger.new($stdout)
|
@@ -53,7 +54,7 @@ module Ej
|
|
53
54
|
bulk_message << source
|
54
55
|
end
|
55
56
|
dest_client.bulk body: bulk_message unless bulk_message.empty?
|
56
|
-
logger.info("
|
57
|
+
logger.info("copy complete #{from + docs.size}/#{total}")
|
57
58
|
num += 1
|
58
59
|
end
|
59
60
|
end
|
@@ -206,6 +207,14 @@ module Ej
|
|
206
207
|
@client.indices.refresh index: @index
|
207
208
|
end
|
208
209
|
|
210
|
+
def nodes_info
|
211
|
+
@client.nodes.info
|
212
|
+
end
|
213
|
+
|
214
|
+
def nodes_stats
|
215
|
+
@client.nodes.stats
|
216
|
+
end
|
217
|
+
|
209
218
|
def bulk(timestamp_key, type, add_timestamp, id_keys, index)
|
210
219
|
data = parse_json(STDIN.read)
|
211
220
|
template = id_keys.map { |key| '%s' }.join('_') unless id_keys.nil?
|
data/lib/ej/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ej
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- toyama0919
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|