ej 0.1.3 → 0.1.4
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.
- checksums.yaml +4 -4
- data/lib/ej/commands.rb +30 -32
- data/lib/ej/core.rb +9 -6
- data/lib/ej/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 551d0015a2a0b74774c85195fdf145f1b531e8c6
|
4
|
+
data.tar.gz: 791210a77c5f2051d745969fc77612e39675f416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdcca2d81f858557e71ca906f790421ac837cbf54c652b542b6aabe6e7492d5cd3ebf8246163842595fa00b080300b47c9dd3b0010e94e8ca4e99d584e8d78f6
|
7
|
+
data.tar.gz: 85d6ca97247aa458b11305393447a9f766ebfa2747b4e626aee4abc554a58ba747af7050e76dfa3ae51b9ae14b771fdab60658a7a9e52b7e068794a8ba722010
|
data/lib/ej/commands.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# coding: utf-8
|
3
|
+
require 'ej/core'
|
3
4
|
require 'thor'
|
4
5
|
require 'yajl'
|
5
|
-
require 'elasticsearch'
|
6
|
-
require 'ej/core'
|
7
|
-
require 'logger'
|
8
6
|
|
9
7
|
module Ej
|
10
8
|
class Commands < Thor
|
11
9
|
class_option :index, aliases: '-i', type: :string, default: '_all', desc: 'index'
|
12
10
|
class_option :host, aliases: '-h', type: :string, default: 'localhost', desc: 'host'
|
13
|
-
class_option :debug, aliases: '-d', type: :
|
11
|
+
class_option :debug, aliases: '-d', type: :boolean, default: false, desc: 'debug mode'
|
14
12
|
|
15
13
|
map '-s' => :search
|
16
14
|
map '-f' => :facet
|
@@ -25,7 +23,7 @@ module Ej
|
|
25
23
|
def initialize(args = [], options = {}, config = {})
|
26
24
|
super(args, options, config)
|
27
25
|
@global_options = config[:shell].base.options
|
28
|
-
@core = Ej::Core.new(@global_options[
|
26
|
+
@core = Ej::Core.new(@global_options[:host], @global_options[:index], @global_options[:debug])
|
29
27
|
end
|
30
28
|
|
31
29
|
desc '-s [lucene query]', 'search'
|
@@ -36,30 +34,30 @@ module Ej
|
|
36
34
|
option :source_only, type: :boolean, aliases: '--so', default: true, desc: 'from'
|
37
35
|
option :query, type: :string, aliases: '-q', default: nil, desc: 'query'
|
38
36
|
option :sort, type: :hash, aliases: '--sort', default: nil, desc: 'ex. --sort @timestamp:desc'
|
39
|
-
def search(query = options[
|
40
|
-
puts_with_format(@core.search(options[
|
37
|
+
def search(query = options[:query])
|
38
|
+
puts_with_format(@core.search(options[:type],
|
41
39
|
query,
|
42
|
-
options[
|
43
|
-
options[
|
44
|
-
options[
|
40
|
+
options[:size],
|
41
|
+
options[:from],
|
42
|
+
options[:source_only],
|
45
43
|
nil,
|
46
|
-
options[
|
47
|
-
options[
|
44
|
+
options[:fields],
|
45
|
+
options[:sort]
|
48
46
|
))
|
49
47
|
end
|
50
48
|
|
51
49
|
desc 'total [lucene query]', 'total'
|
52
50
|
option :type, type: :string, aliases: '-t', default: nil, desc: 'type'
|
53
51
|
option :query, type: :string, aliases: '-q', default: nil, desc: 'query'
|
54
|
-
def count(query = options[
|
55
|
-
puts_with_format(@core.search(options[
|
52
|
+
def count(query = options[:query])
|
53
|
+
puts_with_format(@core.search(options[:type], query, 0, 0, false))
|
56
54
|
end
|
57
55
|
|
58
56
|
desc 'distinct [lucene query]', 'distinct'
|
59
57
|
option :type, type: :string, aliases: '-t', default: nil, desc: 'type'
|
60
58
|
option :query, type: :string, aliases: '-q', default: nil, desc: 'query'
|
61
59
|
def distinct(term)
|
62
|
-
puts_with_format(@core.distinct(term, options[
|
60
|
+
puts_with_format(@core.distinct(term, options[:type], options[:query]))
|
63
61
|
end
|
64
62
|
|
65
63
|
desc 'copy', 'copy index'
|
@@ -71,12 +69,12 @@ module Ej
|
|
71
69
|
option :from, type: :numeric, default: 0, desc: 'from'
|
72
70
|
def copy
|
73
71
|
@core.copy(
|
74
|
-
options[
|
75
|
-
options[
|
76
|
-
options[
|
77
|
-
options[
|
78
|
-
options[
|
79
|
-
options[
|
72
|
+
options[:source],
|
73
|
+
options[:dest],
|
74
|
+
options[:query],
|
75
|
+
options[:per],
|
76
|
+
options[:proc_num],
|
77
|
+
options[:from]
|
80
78
|
)
|
81
79
|
end
|
82
80
|
|
@@ -84,14 +82,14 @@ module Ej
|
|
84
82
|
option :query, type: :string, aliases: '-q', default: nil, desc: 'query'
|
85
83
|
option :per, type: :numeric, default: nil, desc: 'per'
|
86
84
|
def dump
|
87
|
-
@core.dump(options[
|
85
|
+
@core.dump(options[:query], options[:per])
|
88
86
|
end
|
89
87
|
|
90
88
|
desc '-f', 'facet'
|
91
89
|
option :query, type: :string, aliases: '-q', default: '*', desc: 'query'
|
92
90
|
option :size, type: :numeric, aliases: '-n', default: 10, desc: 'size'
|
93
91
|
def facet(term)
|
94
|
-
puts_with_format(@core.facet(term, options[
|
92
|
+
puts_with_format(@core.facet(term, options[:size], options[:query]))
|
95
93
|
end
|
96
94
|
|
97
95
|
desc 'aggs', 'aggs'
|
@@ -99,19 +97,19 @@ module Ej
|
|
99
97
|
option :size, type: :numeric, aliases: '-n', default: 10, desc: 'size'
|
100
98
|
option :terms, type: :array, aliases: '-t', required: true, desc: 'size'
|
101
99
|
def aggs
|
102
|
-
puts_with_format(@core.aggs(options[
|
100
|
+
puts_with_format(@core.aggs(options[:terms], options[:size], options[:query]))
|
103
101
|
end
|
104
102
|
|
105
103
|
desc 'min', 'term'
|
106
104
|
option :term, type: :string, aliases: '-k', desc: 'terms'
|
107
105
|
def min
|
108
|
-
puts_with_format(@core.min(options[
|
106
|
+
puts_with_format(@core.min(options[:term]))
|
109
107
|
end
|
110
108
|
|
111
109
|
desc 'max', 'count record, group by keys'
|
112
110
|
option :term, type: :string, aliases: '-k', desc: 'terms'
|
113
111
|
def max
|
114
|
-
puts_with_format(@core.max(options[
|
112
|
+
puts_with_format(@core.max(options[:term]))
|
115
113
|
end
|
116
114
|
|
117
115
|
desc '-b', 'bulk import STDIN JSON'
|
@@ -121,7 +119,7 @@ module Ej
|
|
121
119
|
option :add_timestamp, type: :boolean, default: true, desc: 'add_timestamp'
|
122
120
|
option :id_keys, type: :array, aliases: '--id', default: nil, desc: 'id'
|
123
121
|
def bulk
|
124
|
-
@core.bulk(options[
|
122
|
+
@core.bulk(options[:timestamp_key], options[:type], options[:add_timestamp], options[:id_keys], options[:index])
|
125
123
|
end
|
126
124
|
|
127
125
|
desc 'health', 'health'
|
@@ -166,8 +164,8 @@ module Ej
|
|
166
164
|
option :type, aliases: '-t', type: :string, default: nil, required: true, desc: 'type'
|
167
165
|
option :path, type: :string, default: nil, required: true, desc: 'path'
|
168
166
|
def put_routing
|
169
|
-
body = { options[
|
170
|
-
puts_with_format(@core.put_mapping(options[
|
167
|
+
body = { options[:type] => {"_routing"=>{"required"=>true, "path"=>options[:path]}}}
|
168
|
+
puts_with_format(@core.put_mapping(options[:index], options[:type], body))
|
171
169
|
end
|
172
170
|
|
173
171
|
desc 'put_template', 'put template'
|
@@ -180,7 +178,7 @@ module Ej
|
|
180
178
|
option :alias, type: :string, aliases: '-a', default: nil, required: true, desc: 'alias name'
|
181
179
|
option :indices, type: :array, aliases: '-x', default: nil, required: true, desc: 'index array'
|
182
180
|
def create_aliases
|
183
|
-
@core.create_aliases(options[
|
181
|
+
@core.create_aliases(options[:alias], options[:indices])
|
184
182
|
end
|
185
183
|
|
186
184
|
desc 'recovery', 'recovery'
|
@@ -193,13 +191,13 @@ module Ej
|
|
193
191
|
option :type, type: :string, aliases: '-t', default: nil, desc: 'type'
|
194
192
|
option :query, type: :string, aliases: '-q', default: nil, desc: 'query'
|
195
193
|
def delete
|
196
|
-
@core.delete(options[
|
194
|
+
@core.delete(options[:index], options[:type], options[:query])
|
197
195
|
end
|
198
196
|
|
199
197
|
desc 'delete_template --name [name]', 'delete_template'
|
200
198
|
option :name, type: :string, default: nil, required: true, desc: 'template name'
|
201
199
|
def delete_template
|
202
|
-
@core.delete_template(options[
|
200
|
+
@core.delete_template(options[:name])
|
203
201
|
end
|
204
202
|
|
205
203
|
desc 'template', 'show template'
|
data/lib/ej/core.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# coding: utf-8
|
3
|
-
require 'yaml'
|
4
3
|
require 'yajl'
|
5
4
|
require 'elasticsearch'
|
6
5
|
require 'hashie'
|
7
|
-
require 'pp'
|
8
6
|
require 'parallel'
|
7
|
+
require 'logger'
|
8
|
+
|
9
|
+
class HashWrapper < ::Hashie::Mash
|
10
|
+
disable_warnings if respond_to?(:disable_warnings)
|
11
|
+
end
|
9
12
|
|
10
13
|
module Ej
|
11
14
|
class Core
|
@@ -32,7 +35,7 @@ module Ej
|
|
32
35
|
search_option = { index: @index, type: type, body: body }
|
33
36
|
search_option[:routing] = routing unless routing.nil?
|
34
37
|
search_option[:_source] = fields.nil? ? nil : fields.join(',')
|
35
|
-
results =
|
38
|
+
results = HashWrapper.new(@client.search(search_option))
|
36
39
|
source_only ? get_sources(results) : results
|
37
40
|
end
|
38
41
|
|
@@ -49,7 +52,7 @@ module Ej
|
|
49
52
|
dest_client = Elasticsearch::Client.new hosts: dest
|
50
53
|
calculate_body = { size: 0 }
|
51
54
|
calculate_body[:query] = { query_string: { query: query } } unless query.nil?
|
52
|
-
calculate_data =
|
55
|
+
calculate_data = HashWrapper.new(source_client.search index: @index, body: calculate_body)
|
53
56
|
total = calculate_data.hits.total
|
54
57
|
payloads = ((total/per) + 1).times.to_a
|
55
58
|
Parallel.map(payloads, in_processes: proc_num) do |num|
|
@@ -60,7 +63,7 @@ module Ej
|
|
60
63
|
end
|
61
64
|
body = { size: per, from: from }
|
62
65
|
body[:query] = { query_string: { query: query } } unless query.nil?
|
63
|
-
data =
|
66
|
+
data = HashWrapper.new(source_client.search index: @index, body: body)
|
64
67
|
docs = data.hits.hits
|
65
68
|
bulk_message = []
|
66
69
|
docs.each do |doc|
|
@@ -86,7 +89,7 @@ module Ej
|
|
86
89
|
from = num * per
|
87
90
|
body = { size: per, from: from }
|
88
91
|
body[:query] = { query_string: { query: query } } unless query.nil?
|
89
|
-
data =
|
92
|
+
data = HashWrapper.new(@client.search index: @index, body: body)
|
90
93
|
docs = data.hits.hits
|
91
94
|
break if docs.empty?
|
92
95
|
docs.each do |doc|
|
data/lib/ej/version.rb
CHANGED