es_tractor 0.0.4 → 0.0.5

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: 4c47c2590ee65edec76531a1d260adc2bcc9c670
4
- data.tar.gz: a1cfa057e7d5b26586fb45c851e75b8fc851bc5b
3
+ metadata.gz: c95803c8427c65509539485cdae392f49ff00373
4
+ data.tar.gz: 7fbf6a5eab0236b6c80bfda83fdfd6bd933a0417
5
5
  SHA512:
6
- metadata.gz: 5423eb837d7ec78e971a183a5b4d1be7afe9a7d2db7193035fe990daa818110dc08027e62fb47c321f1df52dd686509672e6dc0e00051d4ffea64b5ac7a6514f
7
- data.tar.gz: 8c73c999dbec4f9726a03f3596bafeac7931edf6cd5f607dbaa52dd43c164d7e2105eee49e2241f36e8cfb17ca3bcffedc164e69152ba03eeefc560f9039169c
6
+ metadata.gz: 4693b910db8165c76056665d562332a14217f4d7a5fa0538c93df9d80cda4c4b9cbbc0ec104be2b7dea32e0e1ddd5cd32282369f21390e4de7ef89f971da6a1b
7
+ data.tar.gz: 296367c0e4c487087de040ca2def83761098b14af7a3b46dbf68ab959c76a6bdc7f35b77c7b1405c326a75acba5675ef7ada3d5883ae6cbbdc7dd91c8ccf216a
data/.rubocop.yml CHANGED
@@ -1,8 +1,5 @@
1
- Layout/EmptyLineAfterMagicComment:
2
- Enabled: false
3
-
4
1
  AllCops:
5
- TargetRubyVersion: '2.4.1'
2
+ TargetRubyVersion: 2.4
6
3
  Metrics/AbcSize:
7
4
  Max: 20
8
5
  Metrics/BlockLength:
data/History.rdoc CHANGED
@@ -1,3 +1,11 @@
1
+ === 0.0.5 / 2017-10-12
2
+
3
+ * Add fields and sort
4
+
5
+ === 0.0.4 / 2017-09-09
6
+
7
+ * More doc
8
+
1
9
  === 0.0.3 / 2017-09-09
2
10
 
3
11
  * A few enhancements
data/README.rdoc CHANGED
@@ -7,27 +7,50 @@ rdoc :: http://www.rubydoc.info/gems/es_tractor
7
7
 
8
8
  == DESCRIPTION:
9
9
 
10
- es_tractor provides a reduced, simplified and more DRY search API to
11
- Elasticsearch. It aims to facilitate data extraction and preparation
12
- without server scripting.
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
- * Minimal DRY query builder maps root elements of a Hash argument into boolean
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', '~> 0.0.3'
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 FIX
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('utilum', 'oz@utilum.com')
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
@@ -9,7 +9,4 @@ include EsTractor
9
9
  begin
10
10
  require 'pry'
11
11
  Pry.start
12
- rescue LoadError
13
- require 'irb'
14
- IRB.start
15
12
  end
@@ -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[avg cardinality extended_stats geo_bounds geo_centroid max min
158
- percentiles stats sum value_count]
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
- if metrics_aggs.include?(aggregation)
165
- name = [aggregation, opts[aggregation]].join('-').to_sym
166
- aggregations[name] = {
167
- aggregation => { field: opts[aggregation] }
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[exists match query_string range term] & opts.keys)
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
@@ -9,5 +9,5 @@ require 'client'
9
9
  # EsTractor provides tools to query Elasticsearch
10
10
 
11
11
  module EsTractor
12
- VERSION = '0.0.4' # :nodoc:
12
+ VERSION = '0.0.5' # :nodoc:
13
13
  end
data/test/test_client.rb CHANGED
@@ -7,7 +7,7 @@ module EsTractor
7
7
  @tractor = Client.new
8
8
  end
9
9
 
10
- %w[count search].each do |action|
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[my_field my_other_field] }
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[my_field my_other_field],
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[avg cardinality extended_stats geo_bounds geo_centroid max min
133
- percentiles stats sum value_count].each do |aggregation|
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
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
- - utilum
7
+ - Oz Shelach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-09 00:00:00.000000000 Z
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
- es_tractor provides a reduced, simplified and more DRY search API to
117
- Elasticsearch. It aims to facilitate data extraction and preparation
118
- without server scripting.
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: es_tractor provides a reduced, simplified and more DRY search API to Elasticsearch
173
+ summary: Minimal, simple, DRY DSL for searching Elasticsearch
168
174
  test_files: []