ej 0.0.7 → 0.0.8
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 +7 -0
- data/lib/ej/core.rb +27 -10
- 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: c59e2d9ef69659e78965bdf47966eb4dbc290d1b
|
4
|
+
data.tar.gz: 5c38f14f40b51b17b2aadb74764a4e5b385a9d97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a574e5a65c979ab40fabe18b5c3ec74f37d00a7982e1987e916379319b8b87b4901e01c2d2b34875e5a8782a7bda475091b7b4cc9d8a759c5bb3627582a14fc8
|
7
|
+
data.tar.gz: 773b7994f96c5f98ae1782d6189b1816be4f3148317d6ded743bfb77822e5e81044f0186e1c54b32cb78c479687be6690fbc4bd3636aff4510b6499e352d1851
|
data/lib/ej/commands.rb
CHANGED
@@ -73,6 +73,13 @@ module Ej
|
|
73
73
|
puts_json(@core.facet(term, options['size'], options['query']))
|
74
74
|
end
|
75
75
|
|
76
|
+
desc 'aggs', 'aggs'
|
77
|
+
option :query, type: :string, aliases: '-q', default: '*', desc: 'query'
|
78
|
+
option :size, type: :numeric, aliases: '-n', default: 10, desc: 'size'
|
79
|
+
def aggs(term)
|
80
|
+
puts_json(@core.aggs(term, options['size'], options['query']))
|
81
|
+
end
|
82
|
+
|
76
83
|
desc 'min', 'term'
|
77
84
|
option :term, type: :string, aliases: '-k', desc: 'terms'
|
78
85
|
def min
|
data/lib/ej/core.rb
CHANGED
@@ -8,9 +8,9 @@ require 'pp'
|
|
8
8
|
|
9
9
|
module Ej
|
10
10
|
class Core
|
11
|
+
DEFAULT_PER = 30000
|
11
12
|
def initialize(host, index, debug)
|
12
|
-
@logger = Logger.new($stderr)
|
13
|
-
@logger.level = debug ? Logger::DEBUG : Logger::INFO
|
13
|
+
@logger = debug ? Logger.new($stderr) : nil
|
14
14
|
@index = index
|
15
15
|
@client = Elasticsearch::Client.new hosts: host, logger: @logger, index: @index
|
16
16
|
end
|
@@ -32,30 +32,34 @@ module Ej
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def move(source, dest, query)
|
35
|
-
per =
|
36
|
-
source_client = Elasticsearch::Client.new hosts: source, index: @index, logger: @logger
|
37
|
-
dest_client = Elasticsearch::Client.new hosts: dest, logger: @logger
|
35
|
+
per = DEFAULT_PER
|
38
36
|
num = 0
|
37
|
+
logger = Logger.new($stdout)
|
38
|
+
source_client = Elasticsearch::Client.new hosts: source, index: @index
|
39
|
+
dest_client = Elasticsearch::Client.new hosts: dest
|
39
40
|
while true
|
40
41
|
from = num * per
|
41
42
|
body = { size: per, from: from }
|
42
43
|
body[:query] = { query_string: { query: query } } unless query.nil?
|
43
44
|
data = Hashie::Mash.new(source_client.search index: @index, body: body)
|
44
|
-
|
45
|
+
docs = data.hits.hits
|
46
|
+
total = data.hits.total
|
47
|
+
break if docs.empty?
|
45
48
|
bulk_message = []
|
46
|
-
|
49
|
+
docs.each do |doc|
|
47
50
|
source = doc.delete('_source')
|
48
51
|
doc.delete('_score')
|
49
52
|
bulk_message << { index: doc.to_h }
|
50
53
|
bulk_message << source
|
51
54
|
end
|
52
55
|
dest_client.bulk body: bulk_message unless bulk_message.empty?
|
56
|
+
logger.info("move complete #{from + docs.size}/#{total}")
|
53
57
|
num += 1
|
54
58
|
end
|
55
59
|
end
|
56
60
|
|
57
61
|
def dump(query)
|
58
|
-
per =
|
62
|
+
per = DEFAULT_PER
|
59
63
|
num = 0
|
60
64
|
bulk_message = []
|
61
65
|
while true
|
@@ -63,8 +67,9 @@ module Ej
|
|
63
67
|
body = { size: per, from: from }
|
64
68
|
body[:query] = { query_string: { query: query } } unless query.nil?
|
65
69
|
data = Hashie::Mash.new(@client.search index: @index, body: body)
|
66
|
-
|
67
|
-
|
70
|
+
docs = data.hits.hits
|
71
|
+
break if docs.empty?
|
72
|
+
docs.each do |doc|
|
68
73
|
source = doc.delete('_source')
|
69
74
|
doc.delete('_score')
|
70
75
|
bulk_message << Yajl::Encoder.encode({ 'index' => doc.to_h })
|
@@ -91,6 +96,18 @@ module Ej
|
|
91
96
|
@client.search index: @index, body: body
|
92
97
|
end
|
93
98
|
|
99
|
+
def aggs(term, size, query)
|
100
|
+
body = {"size"=>0,
|
101
|
+
"query"=>
|
102
|
+
{"filtered"=>
|
103
|
+
{"query"=>{"query_string"=>{"query"=> query}},
|
104
|
+
"filter"=>{"bool"=>{"must"=>[], "must_not"=>[]}}}},
|
105
|
+
"aggs"=>
|
106
|
+
{"agg_" + term =>
|
107
|
+
{"terms"=>{"field"=>term, "size"=>size, "order"=>{"_count"=>"desc"}}}}}
|
108
|
+
@client.search index: @index, body: body
|
109
|
+
end
|
110
|
+
|
94
111
|
def min(term)
|
95
112
|
body = {
|
96
113
|
aggs: {
|
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.8
|
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-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|