es_tractor 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +4 -0
- data/lib/es_tractor.rb +2 -1
- data/lib/es_tractor/client.rb +8 -3
- data/test/helper.rb +1 -0
- data/test/test_client.rb +55 -16
- data/test/test_es_tractor.rb +1 -0
- 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: 81b24cb42d1f02473ff67c94f7bac55727670db8
|
4
|
+
data.tar.gz: f0050eb804dad31fdc1ebb054c7ba2cf3cd845cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a203a98c2fa74ae46cdb05f3ed146af4abec25c5f6605b0ed6b362413e8cfac16b27261e03dc1b47887648968b59013067e9cd63c476c04e396af6a3a84a9ccf
|
7
|
+
data.tar.gz: dec2d62a0179aef4608c3544b50dcb97707cc6daba78447a107725caeed63f8a7428864ed275bbc4e9e5a5d55aaff0646c383102268a1c7a7357fe2393d44174
|
data/History.rdoc
CHANGED
data/lib/es_tractor.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
$LOAD_PATH.unshift File.dirname(__FILE__) + '/es_tractor'
|
3
4
|
$LOAD_PATH.unshift File.dirname(__FILE__) \
|
4
5
|
unless $LOAD_PATH.include?(File.dirname(__FILE__))
|
@@ -9,5 +10,5 @@ require 'client'
|
|
9
10
|
# EsTractor provides tools to query Elasticsearch
|
10
11
|
|
11
12
|
module EsTractor
|
12
|
-
VERSION = '0.0.
|
13
|
+
VERSION = '0.0.6' # :nodoc:
|
13
14
|
end
|
data/lib/es_tractor/client.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'elasticsearch'
|
3
4
|
|
4
5
|
module EsTractor
|
@@ -122,6 +123,8 @@ module EsTractor
|
|
122
123
|
# Field name on which to apply the cardinality aggregation
|
123
124
|
# @option opts [String] :extended_stats
|
124
125
|
# Field name on which to apply the extended_stats aggregation
|
126
|
+
# @option opts [Array] :fields
|
127
|
+
# Field names to return
|
125
128
|
# @option opts [String] :geo_bounds
|
126
129
|
# Field name on which to apply the geo_bounds aggregation
|
127
130
|
# @option opts [String] :geo_centroid
|
@@ -132,6 +135,8 @@ module EsTractor
|
|
132
135
|
# Field name on which to apply the min aggregation
|
133
136
|
# @option opts [String] :percentiles
|
134
137
|
# Field name on which to apply the percentiles aggregation
|
138
|
+
# @option opts [Array] :sort
|
139
|
+
# Contains Hashes keyd on field name
|
135
140
|
# @option opts [String] :stats
|
136
141
|
# Field name on which to apply the stats aggregation
|
137
142
|
# @option opts [String] :sum
|
@@ -154,8 +159,8 @@ module EsTractor
|
|
154
159
|
end
|
155
160
|
|
156
161
|
def metrics_aggs
|
157
|
-
%i
|
158
|
-
percentiles stats sum value_count
|
162
|
+
%i[avg cardinality extended_stats geo_bounds geo_centroid max min
|
163
|
+
percentiles stats sum value_count]
|
159
164
|
end
|
160
165
|
|
161
166
|
def aggs(opts)
|
@@ -191,7 +196,7 @@ module EsTractor
|
|
191
196
|
def query(opts = {})
|
192
197
|
bool = { filter: [], must: [] }
|
193
198
|
|
194
|
-
(%i
|
199
|
+
(%i[exists match query_string range term] & opts.keys)
|
195
200
|
.each do |qualifier|
|
196
201
|
case qualifier
|
197
202
|
when :exists
|
data/test/helper.rb
CHANGED
data/test/test_client.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'helper'
|
3
4
|
|
4
5
|
module EsTractor
|
@@ -7,7 +8,7 @@ module EsTractor
|
|
7
8
|
@tractor = Client.new
|
8
9
|
end
|
9
10
|
|
10
|
-
%w
|
11
|
+
%w[count search].each do |action|
|
11
12
|
exp = action == 'search' ? { from: 0, size: 0 } : {}
|
12
13
|
|
13
14
|
define_method "test_#{action}_with_term_hash" do
|
@@ -94,14 +95,14 @@ module EsTractor
|
|
94
95
|
end
|
95
96
|
|
96
97
|
define_method "test_#{action}_with_exists_fieldname_array" do
|
97
|
-
opts = { exists: %w
|
98
|
+
opts = { exists: %w[my_field my_other_field] }
|
98
99
|
exp[:body] = { query: {
|
99
100
|
bool: {
|
100
101
|
must: [],
|
101
102
|
filter: [
|
102
103
|
{
|
103
104
|
exists: {
|
104
|
-
field: %w
|
105
|
+
field: %w[my_field my_other_field],
|
105
106
|
},
|
106
107
|
},
|
107
108
|
],
|
@@ -129,10 +130,52 @@ module EsTractor
|
|
129
130
|
|
130
131
|
next unless action == 'search'
|
131
132
|
|
132
|
-
|
133
|
+
def test_search_with_fields_arg
|
134
|
+
opts = { fields: [:some_field] }
|
135
|
+
exp = {
|
136
|
+
from: 0,
|
137
|
+
size: 0,
|
138
|
+
body: {
|
139
|
+
query: {
|
140
|
+
bool: {
|
141
|
+
filter: [],
|
142
|
+
must: [],
|
143
|
+
},
|
144
|
+
},
|
145
|
+
fields: [:some_field]
|
146
|
+
},
|
147
|
+
}
|
148
|
+
|
149
|
+
@tractor.client.expects(:search).with(exp)
|
150
|
+
|
151
|
+
@tractor.search opts
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_search_with_sort_arg
|
155
|
+
opts = { sort: [:some_field] }
|
156
|
+
exp = {
|
157
|
+
from: 0,
|
158
|
+
size: 0,
|
159
|
+
body: {
|
160
|
+
query: {
|
161
|
+
bool: {
|
162
|
+
filter: [],
|
163
|
+
must: [],
|
164
|
+
},
|
165
|
+
},
|
166
|
+
sort: [:some_field]
|
167
|
+
},
|
168
|
+
}
|
169
|
+
|
170
|
+
@tractor.client.expects(:search).with(exp)
|
171
|
+
|
172
|
+
@tractor.search opts
|
173
|
+
end
|
174
|
+
|
175
|
+
%i[
|
133
176
|
avg cardinality extended_stats geo_bounds geo_centroid max min
|
134
177
|
percentiles stats sum value_count
|
135
|
-
|
178
|
+
].each do |aggregation|
|
136
179
|
define_method "test_search_with_#{aggregation}_agg" do
|
137
180
|
opts = {
|
138
181
|
query_string: 'My query string',
|
@@ -142,17 +185,13 @@ module EsTractor
|
|
142
185
|
from: 0,
|
143
186
|
size: 0,
|
144
187
|
body: {
|
145
|
-
query: {
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
"#{aggregation}-grade".to_sym => {
|
153
|
-
aggregation => { field: 'grade' }
|
154
|
-
},
|
155
|
-
},
|
188
|
+
query: { bool: {
|
189
|
+
must: [query_string: { query: 'My query string' }],
|
190
|
+
filter: [],
|
191
|
+
}, },
|
192
|
+
aggs: { "#{aggregation}-grade".to_sym => {
|
193
|
+
aggregation => { field: 'grade' }
|
194
|
+
}, },
|
156
195
|
},
|
157
196
|
}
|
158
197
|
|
data/test/test_es_tractor.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: es_tractor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oz Shelach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch
|