ej 0.1.2 → 0.1.3

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: f0b332b7857e660bfaf5210b79033873d69d664f
4
- data.tar.gz: 9692b219550391e6e63a8c52d96ae633e4d13845
3
+ metadata.gz: 643e3d4fc75c7f83f484f89845d0fcf4b75433a1
4
+ data.tar.gz: d65079cd2e20a88ba694ad20d8ee8db48d50df24
5
5
  SHA512:
6
- metadata.gz: 82f065af8c92d75f3a0e613466e38cc9216dbe4811610762fc852bac1c528ffa71d16f38fdd21ececb79f917203db3562cd3204f03ba7439dea1f9f6d5e77fb4
7
- data.tar.gz: 85e4ef0bc16bf929609025e84cc0c9725bee86a2efb5eb3a15b8451cc90a383673af6f11fee1665ce78a7103fa9f65ed92bdee7c4d2e99956542779cb735ca6a
6
+ metadata.gz: aeb5afcd34843b5caef5d53a408d05a42f2a4a5db6367198bf6ff6ce17c6c14fe224dbd460c123e7a2fd885506929835044056f450d61b632e008378f09083b9
7
+ data.tar.gz: a47937f3958993b8809c537c2b381da730de01a82b96918ff6cf8677ce46661ee64bfc84d49a927113d6f9d9cc10f382f3f0907f2bd3152395eade6d3595a82c
@@ -20,7 +20,6 @@ module Ej
20
20
  map '-a' => :aliases
21
21
  map '-m' => :mapping
22
22
  map '-e' => :debug_eval
23
- map '--j2h' => :json_to_hash
24
23
  map '--health' => :health
25
24
 
26
25
  def initialize(args = [], options = {}, config = {})
@@ -98,8 +97,9 @@ module Ej
98
97
  desc 'aggs', 'aggs'
99
98
  option :query, type: :string, aliases: '-q', default: '*', desc: 'query'
100
99
  option :size, type: :numeric, aliases: '-n', default: 10, desc: 'size'
101
- def aggs(term)
102
- puts_with_format(@core.aggs(term, options['size'], options['query']))
100
+ option :terms, type: :array, aliases: '-t', required: true, desc: 'size'
101
+ def aggs
102
+ puts_with_format(@core.aggs(options['terms'], options['size'], options['query']))
103
103
  end
104
104
 
105
105
  desc 'min', 'term'
@@ -232,11 +232,6 @@ module Ej
232
232
  puts_with_format @core.nodes_stats
233
233
  end
234
234
 
235
- desc '--j2h', 'json to hash'
236
- def json_to_hash
237
- pp Yajl::Parser.parse(STDIN.read)
238
- end
239
-
240
235
  private
241
236
 
242
237
  def puts_with_format(object)
@@ -116,17 +116,37 @@ module Ej
116
116
  @client.search index: @index, body: body
117
117
  end
118
118
 
119
- def aggs(term, size, query)
120
- body = {"size"=>0,
121
- "query"=>
122
- {"filtered"=>
123
- {"query"=>{"query_string"=>{"query"=> query}},
124
- "filter"=>{"bool"=>{"must"=>[], "must_not"=>[]}}}},
125
- "aggs"=>
126
- {"agg_" + term =>
127
- {"terms"=>{"field"=>term, "size"=>size, "order"=>{"_count"=>"desc"}}}}}
128
- results = @client.search index: @index, body: body
129
- results['aggregations']["agg_" + term]['buckets']
119
+ def aggs(terms, size, query)
120
+ body = {
121
+ "size"=>0,
122
+ "query"=>{
123
+ "query_string"=>{
124
+ "query"=>query
125
+ }
126
+ }
127
+ }
128
+
129
+ agg_terms = []
130
+ code = %Q{['aggs']}
131
+ terms.each_with_index do |term, i|
132
+ term_name = "agg_#{term}"
133
+ aggs_body = {
134
+ term_name=>{
135
+ "terms"=>{
136
+ "field"=>term,
137
+ "size"=>size,
138
+ "order"=>{
139
+ "_count"=>"desc"
140
+ }
141
+ }
142
+ }
143
+ }
144
+
145
+ eval(%Q{body#{code} = aggs_body})
146
+ code += %Q{['#{term_name}']['aggs']}
147
+ end
148
+
149
+ @client.search index: @index, body: body
130
150
  end
131
151
 
132
152
  def min(term)
@@ -1,3 +1,3 @@
1
1
  module Ej
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
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.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - toyama0919
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-03 00:00:00.000000000 Z
11
+ date: 2017-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler