es_tractor 0.0.4 → 0.0.5
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/.rubocop.yml +1 -4
- data/History.rdoc +8 -0
- data/README.rdoc +37 -12
- data/Rakefile +3 -3
- data/bin/console +0 -3
- data/lib/es_tractor/client.rb +10 -10
- data/lib/es_tractor.rb +1 -1
- data/test/test_client.rb +7 -5
- metadata +14 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c95803c8427c65509539485cdae392f49ff00373
|
4
|
+
data.tar.gz: 7fbf6a5eab0236b6c80bfda83fdfd6bd933a0417
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4693b910db8165c76056665d562332a14217f4d7a5fa0538c93df9d80cda4c4b9cbbc0ec104be2b7dea32e0e1ddd5cd32282369f21390e4de7ef89f971da6a1b
|
7
|
+
data.tar.gz: 296367c0e4c487087de040ca2def83761098b14af7a3b46dbf68ab959c76a6bdc7f35b77c7b1405c326a75acba5675ef7ada3d5883ae6cbbdc7dd91c8ccf216a
|
data/.rubocop.yml
CHANGED
data/History.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -7,27 +7,50 @@ rdoc :: http://www.rubydoc.info/gems/es_tractor
|
|
7
7
|
|
8
8
|
== DESCRIPTION:
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
Minimal, simple, DRY DSL for searching Elasticsearch.
|
11
|
+
|
12
|
+
Takes one shallow hash argument and translates it to an elaborate one passed
|
13
|
+
on to elasticsearch-api. The price: narrower options. The gain: succinctness.
|
14
|
+
For example, a root <tt>:range</tt> is always a boolean filter and always
|
15
|
+
includes the edges:
|
16
|
+
|
17
|
+
tractor = Client.new
|
18
|
+
opts = { range: { timestamp: ['now-5m', 'now'] } }
|
19
|
+
|
20
|
+
tractor.search(opts) # => sends the following to Ealsticsearch:
|
21
|
+
{
|
22
|
+
"query": {
|
23
|
+
"bool": {
|
24
|
+
"filter": [
|
25
|
+
{
|
26
|
+
"range": {
|
27
|
+
"timestamp": {
|
28
|
+
"gte":"now-5m",
|
29
|
+
"lte":"now"
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
],
|
34
|
+
"must": [],
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
13
39
|
|
14
40
|
== FEATURES/PROBLEMS:
|
15
41
|
|
16
|
-
* Subset of Search APIs: count, search, aggregations.
|
42
|
+
* Subset of Search APIs: count, fields, search, sort, aggregations.
|
17
43
|
* Supports most metrics aggregations without optional parameters.
|
18
|
-
*
|
44
|
+
* Query builder translates a simplified Hash argument into boolean
|
19
45
|
filters and aggregations.
|
20
46
|
|
21
47
|
* TODO:
|
22
|
-
* Aggregations:
|
48
|
+
* Aggregations:
|
23
49
|
* Bucket
|
24
50
|
* Nesting
|
25
51
|
* Optional parameters
|
26
52
|
* Add Search APIs:
|
27
|
-
* Fields
|
28
|
-
* Sort
|
29
53
|
* Scroll
|
30
|
-
* Report formats: CSV, JSON.
|
31
54
|
* Extraction: Aggregation to flat records (separate project?).
|
32
55
|
|
33
56
|
== SYNOPSIS:
|
@@ -42,7 +65,7 @@ without server scripting.
|
|
42
65
|
# => (Integer) number of documents where my_field == 'my precise term'
|
43
66
|
|
44
67
|
tractor = Client.new true
|
45
|
-
tractor.search(size: 1, term: { my_field: 'my precise term' }) # =>
|
68
|
+
tractor.search(size: 1, term: { my_field: 'my precise term' }) # =>
|
46
69
|
{
|
47
70
|
"took"=>29,
|
48
71
|
"timed_out"=>false,
|
@@ -66,6 +89,8 @@ without server scripting.
|
|
66
89
|
|
67
90
|
== REQUIREMENTS:
|
68
91
|
|
92
|
+
* Ruby 2.0+
|
93
|
+
|
69
94
|
Some environment variables are expected:
|
70
95
|
* ES_TRACTOR_ELASTICSEARCH_HOST
|
71
96
|
* ES_TRACTOR_ELASTICSEARCH_INDEX
|
@@ -75,7 +100,7 @@ Some environment variables are expected:
|
|
75
100
|
$ gem install es_tractor
|
76
101
|
|
77
102
|
Or in your Gemfile:
|
78
|
-
gem 'es_tractor'
|
103
|
+
gem 'es_tractor'
|
79
104
|
|
80
105
|
== DEVELOPERS:
|
81
106
|
|
@@ -90,7 +115,7 @@ generate the RDoc.
|
|
90
115
|
|
91
116
|
(The MIT License)
|
92
117
|
|
93
|
-
Copyright (c) 2017
|
118
|
+
Copyright (c) 2017 Oz Shelach
|
94
119
|
|
95
120
|
Permission is hereby granted, free of charge, to any person obtaining
|
96
121
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ require 'hoe'
|
|
7
7
|
Hoe.plugin :yard
|
8
8
|
|
9
9
|
Hoe.spec 'es_tractor' do
|
10
|
-
developer('
|
10
|
+
developer('Oz Shelach', 'oz@utilum.com')
|
11
11
|
|
12
12
|
license 'MIT'
|
13
13
|
|
@@ -29,9 +29,9 @@ namespace :es_tractor do
|
|
29
29
|
namespace :demo do
|
30
30
|
desc 'Count all docuements since forever'
|
31
31
|
task :count_all do
|
32
|
-
tractor = Client.new
|
32
|
+
tractor = Client.new true
|
33
33
|
r = tractor.count
|
34
|
-
puts "Found #{r} documents"
|
34
|
+
puts "Found #{r['count']} documents"
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
data/bin/console
CHANGED
data/lib/es_tractor/client.rb
CHANGED
@@ -76,7 +76,7 @@ module EsTractor
|
|
76
76
|
# aggregations keys.
|
77
77
|
#
|
78
78
|
# Supported aggregations (avg, cardinality, extended_stats, geo_bounds,
|
79
|
-
# geo_centroid, max min, percentiles, stats, sum, value_count) take
|
79
|
+
# geo_centroid, max min, percentiles, stats, sum, value_count) take
|
80
80
|
# a field name and are automatically named.
|
81
81
|
# @example
|
82
82
|
# opts = {
|
@@ -154,19 +154,17 @@ module EsTractor
|
|
154
154
|
end
|
155
155
|
|
156
156
|
def metrics_aggs
|
157
|
-
%i
|
158
|
-
|
157
|
+
%i(avg cardinality extended_stats geo_bounds geo_centroid max min
|
158
|
+
percentiles stats sum value_count)
|
159
159
|
end
|
160
160
|
|
161
161
|
def aggs(opts)
|
162
162
|
aggregations = {}
|
163
163
|
(supported_aggs & opts.keys).each do |aggregation|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
}
|
169
|
-
end
|
164
|
+
name = [aggregation, opts[aggregation]].join('-').to_sym
|
165
|
+
aggregations[name] = {
|
166
|
+
aggregation => { field: opts[aggregation] }
|
167
|
+
}
|
170
168
|
end
|
171
169
|
aggregations
|
172
170
|
end
|
@@ -184,6 +182,8 @@ module EsTractor
|
|
184
182
|
|
185
183
|
def body(opts = {})
|
186
184
|
body = { query: query(opts) }
|
185
|
+
body[:fields] = opts[:fields] if opts[:fields]
|
186
|
+
body[:sort] = opts[:sort] if opts[:sort]
|
187
187
|
body[:aggs] = aggs(opts) if (supported_aggs & opts.keys).any?
|
188
188
|
body
|
189
189
|
end
|
@@ -191,7 +191,7 @@ module EsTractor
|
|
191
191
|
def query(opts = {})
|
192
192
|
bool = { filter: [], must: [] }
|
193
193
|
|
194
|
-
(%i
|
194
|
+
(%i(exists match query_string range term) & opts.keys)
|
195
195
|
.each do |qualifier|
|
196
196
|
case qualifier
|
197
197
|
when :exists
|
data/lib/es_tractor.rb
CHANGED
data/test/test_client.rb
CHANGED
@@ -7,7 +7,7 @@ module EsTractor
|
|
7
7
|
@tractor = Client.new
|
8
8
|
end
|
9
9
|
|
10
|
-
%w
|
10
|
+
%w(count search).each do |action|
|
11
11
|
exp = action == 'search' ? { from: 0, size: 0 } : {}
|
12
12
|
|
13
13
|
define_method "test_#{action}_with_term_hash" do
|
@@ -94,14 +94,14 @@ module EsTractor
|
|
94
94
|
end
|
95
95
|
|
96
96
|
define_method "test_#{action}_with_exists_fieldname_array" do
|
97
|
-
opts = { exists: %w
|
97
|
+
opts = { exists: %w(my_field my_other_field) }
|
98
98
|
exp[:body] = { query: {
|
99
99
|
bool: {
|
100
100
|
must: [],
|
101
101
|
filter: [
|
102
102
|
{
|
103
103
|
exists: {
|
104
|
-
field: %w
|
104
|
+
field: %w(my_field my_other_field),
|
105
105
|
},
|
106
106
|
},
|
107
107
|
],
|
@@ -129,8 +129,10 @@ module EsTractor
|
|
129
129
|
|
130
130
|
next unless action == 'search'
|
131
131
|
|
132
|
-
%i
|
133
|
-
|
132
|
+
%i(
|
133
|
+
avg cardinality extended_stats geo_bounds geo_centroid max min
|
134
|
+
percentiles stats sum value_count
|
135
|
+
).each do |aggregation|
|
134
136
|
define_method "test_search_with_#{aggregation}_agg" do
|
135
137
|
opts = {
|
136
138
|
query_string: 'My query string',
|
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.5
|
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-
|
11
|
+
date: 2017-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch
|
@@ -112,10 +112,16 @@ dependencies:
|
|
112
112
|
- - "~>"
|
113
113
|
- !ruby/object:Gem::Version
|
114
114
|
version: '3.16'
|
115
|
-
description:
|
116
|
-
|
117
|
-
|
118
|
-
|
115
|
+
description: "Minimal, simple, DRY DSL for searching Elasticsearch.\n\nTakes one shallow
|
116
|
+
hash argument and translates it to an elaborate one passed\non to elasticsearch-api.
|
117
|
+
The price: narrower options. The gain: succinctness.\nFor example, a root <tt>:range</tt>
|
118
|
+
is always a boolean filter and always \nincludes the edges:\n\n tractor = Client.new\n
|
119
|
+
\ opts = { range: { timestamp: ['now-5m', 'now'] } }\n\n tractor.search(opts) #
|
120
|
+
=> sends the following to Ealsticsearch:\n {\n \"query\": {\n \"bool\":
|
121
|
+
{\n \"filter\": [\n {\n \"range\": {\n \"timestamp\":
|
122
|
+
{\n \"gte\":\"now-5m\",\n \"lte\":\"now\"\n }\n
|
123
|
+
\ }\n }\n ],\n \"must\": [],\n }\n }\n
|
124
|
+
\ }"
|
119
125
|
email:
|
120
126
|
- oz@utilum.com
|
121
127
|
executables:
|
@@ -164,5 +170,5 @@ rubyforge_project:
|
|
164
170
|
rubygems_version: 2.6.13
|
165
171
|
signing_key:
|
166
172
|
specification_version: 4
|
167
|
-
summary:
|
173
|
+
summary: Minimal, simple, DRY DSL for searching Elasticsearch
|
168
174
|
test_files: []
|