ej 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 643e3d4fc75c7f83f484f89845d0fcf4b75433a1
4
- data.tar.gz: d65079cd2e20a88ba694ad20d8ee8db48d50df24
3
+ metadata.gz: 551d0015a2a0b74774c85195fdf145f1b531e8c6
4
+ data.tar.gz: 791210a77c5f2051d745969fc77612e39675f416
5
5
  SHA512:
6
- metadata.gz: aeb5afcd34843b5caef5d53a408d05a42f2a4a5db6367198bf6ff6ce17c6c14fe224dbd460c123e7a2fd885506929835044056f450d61b632e008378f09083b9
7
- data.tar.gz: a47937f3958993b8809c537c2b381da730de01a82b96918ff6cf8677ce46661ee64bfc84d49a927113d6f9d9cc10f382f3f0907f2bd3152395eade6d3595a82c
6
+ metadata.gz: cdcca2d81f858557e71ca906f790421ac837cbf54c652b542b6aabe6e7492d5cd3ebf8246163842595fa00b080300b47c9dd3b0010e94e8ca4e99d584e8d78f6
7
+ data.tar.gz: 85d6ca97247aa458b11305393447a9f766ebfa2747b4e626aee4abc554a58ba747af7050e76dfa3ae51b9ae14b771fdab60658a7a9e52b7e068794a8ba722010
@@ -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: :string, default: false, desc: 'debug mode'
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['host'], @global_options['index'], @global_options['debug'])
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['query'])
40
- puts_with_format(@core.search(options['type'],
37
+ def search(query = options[:query])
38
+ puts_with_format(@core.search(options[:type],
41
39
  query,
42
- options['size'],
43
- options['from'],
44
- options['source_only'],
40
+ options[:size],
41
+ options[:from],
42
+ options[:source_only],
45
43
  nil,
46
- options['fields'],
47
- options['sort']
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['query'])
55
- puts_with_format(@core.search(options['type'], query, 0, 0, false))
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['type'], options['query']))
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['source'],
75
- options['dest'],
76
- options['query'],
77
- options['per'],
78
- options['proc_num'],
79
- options['from']
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['query'], options['per'])
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['size'], options['query']))
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['terms'], options['size'], options['query']))
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['term']))
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['term']))
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['timestamp_key'], options['type'], options['add_timestamp'], options['id_keys'], options['index'])
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['type'] => {"_routing"=>{"required"=>true, "path"=>options['path']}}}
170
- puts_with_format(@core.put_mapping(options['index'], options['type'], body))
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['alias'], options['indices'])
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['index'], options['type'], options['query'])
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['name'])
200
+ @core.delete_template(options[:name])
203
201
  end
204
202
 
205
203
  desc 'template', 'show template'
@@ -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 = Hashie::Mash.new(@client.search(search_option))
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 = Hashie::Mash.new(source_client.search index: @index, body: calculate_body)
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 = Hashie::Mash.new(source_client.search index: @index, body: body)
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 = Hashie::Mash.new(@client.search index: @index, body: body)
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|
@@ -1,3 +1,3 @@
1
1
  module Ej
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ej
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - toyama0919