es_tractor 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0c7612550a240d22377140293d1360e419f7223
4
- data.tar.gz: 2037664523b539a9f40c20f9a7672c7736293fe3
3
+ metadata.gz: 4c47c2590ee65edec76531a1d260adc2bcc9c670
4
+ data.tar.gz: a1cfa057e7d5b26586fb45c851e75b8fc851bc5b
5
5
  SHA512:
6
- metadata.gz: eb989abd3b4a9340740f2e5c6da3a9a17779296b304bd95a823b4a44b219b5ca2c7a422e898175d99a51a338ff56ce1caee427e67bbc62b3b36c9cb80e97730c
7
- data.tar.gz: ee3e75992f0fd8503b96c08f0cfa0ab2e1879f8c5e729ca68948c9e17891634e4598b78089bcc63378bf4d487634422347d920bf70d3a8b097a1d5505e723f33
6
+ metadata.gz: 5423eb837d7ec78e971a183a5b4d1be7afe9a7d2db7193035fe990daa818110dc08027e62fb47c321f1df52dd686509672e6dc0e00051d4ffea64b5ac7a6514f
7
+ data.tar.gz: 8c73c999dbec4f9726a03f3596bafeac7931edf6cd5f607dbaa52dd43c164d7e2105eee49e2241f36e8cfb17ca3bcffedc164e69152ba03eeefc560f9039169c
data/README.rdoc CHANGED
@@ -1,6 +1,7 @@
1
1
  = EsTractor: Simplified data extracton from Elasticsearch
2
2
 
3
- home :: https://github.com/utilum/es_tractor
3
+ home :: https://rubygems.org/gems/es_tractor
4
+ dev :: https://github.com/utilum/es_tractor/tree/dev
4
5
  bugs :: https://github.com/utilum/es_tractor/issues
5
6
  rdoc :: http://www.rubydoc.info/gems/es_tractor
6
7
 
@@ -12,10 +13,10 @@ without server scripting.
12
13
 
13
14
  == FEATURES/PROBLEMS:
14
15
 
15
- * Subset of Search APIs: count, search.
16
- * Most metrics aggregations without optional parameters
16
+ * Subset of Search APIs: count, search, aggregations.
17
+ * Supports most metrics aggregations without optional parameters.
17
18
  * Minimal DRY query builder maps root elements of a Hash argument into boolean
18
- filters.
19
+ filters and aggregations.
19
20
 
20
21
  * TODO:
21
22
  * Aggregations:
@@ -40,28 +41,28 @@ without server scripting.
40
41
  tractor.count(term: { my_field: 'my precise term' })
41
42
  # => (Integer) number of documents where my_field == 'my precise term'
42
43
 
43
- tractor.search(size: 1, term: { my_field: 'my precise term' })
44
- # =>
45
- # {
46
- # "took"=>29,
47
- # "timed_out"=>false,
48
- # "_shards"=>{"total"=>542, "successful"=>542, "failed"=>0},
49
- # "hits"=> {
50
- # "total"=>279271,
51
- # "max_score"=>0.0,
52
- # "hits"=> [
53
- # {
54
- # "_index"=>"my_index",
55
- # "_id"=>"bc596ff2-955b-11e7-a7d2-001ed3f963a9",
56
- # "_score"=>1.6272357,
57
- # "_source"=> {
58
- # "my_field"=>"my precise term",
59
- # "timestamp"=>"2017-09-09 12:38:09.263",
60
- # },
61
- # },
62
- # ],
63
- # },
64
- # }
44
+ tractor = Client.new true
45
+ tractor.search(size: 1, term: { my_field: 'my precise term' }) # =>
46
+ {
47
+ "took"=>29,
48
+ "timed_out"=>false,
49
+ "_shards"=>{"total"=>542, "successful"=>542, "failed"=>0},
50
+ "hits"=> {
51
+ "total"=>279271,
52
+ "max_score"=>0.0,
53
+ "hits"=> [
54
+ {
55
+ "_index"=>"my_index",
56
+ "_id"=>"bc596ff2-955b-11e7-a7d2-001ed3f963a9",
57
+ "_score"=>0.0,
58
+ "_source"=> {
59
+ "my_field"=>"my precise term",
60
+ "timestamp"=>"2017-09-09 12:38:09.263",
61
+ },
62
+ },
63
+ ],
64
+ },
65
+ }
65
66
 
66
67
  == REQUIREMENTS:
67
68
 
@@ -69,6 +70,13 @@ Some environment variables are expected:
69
70
  * ES_TRACTOR_ELASTICSEARCH_HOST
70
71
  * ES_TRACTOR_ELASTICSEARCH_INDEX
71
72
 
73
+ == INSTALL:
74
+
75
+ $ gem install es_tractor
76
+
77
+ Or in your Gemfile:
78
+ gem 'es_tractor', '~> 0.0.3'
79
+
72
80
  == DEVELOPERS:
73
81
 
74
82
  After checking out the source, run:
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('oz', 'oz@utilum.com')
10
+ developer('utilum', 'oz@utilum.com')
11
11
 
12
12
  license 'MIT'
13
13
 
data/bin/console CHANGED
@@ -4,6 +4,8 @@
4
4
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
5
5
  require 'es_tractor'
6
6
 
7
+ include EsTractor
8
+
7
9
  begin
8
10
  require 'pry'
9
11
  Pry.start
@@ -42,42 +42,102 @@ module EsTractor
42
42
  #
43
43
  # @example
44
44
  # opts = {
45
- # match: { color: 'strawberry black' },
46
- # exists: ['flavor', 'spicy'],
45
+ # match: { topping: 'fudge' },
46
+ # exists: ['address', 'phone'],
47
47
  # term: [
48
48
  # { flavor: 'vanilla' },
49
- # { spicy: 3 },
49
+ # { scoops: 3 },
50
50
  # ],
51
51
  # }
52
52
  #
53
53
  # Client.new.count(opts) # => { 'count' => 7 }
54
54
  #
55
55
  # # Tranforms opts into the following hash, passed to Elasticsearch:
56
- # {
57
- # body: {
58
- # query: {
59
- # bool: {
60
- # must: {
61
- # match: { flavor: 'vanilla' },
62
- # },
63
- # filter: [
64
- # { term: { flavor: 'vanilla' } },
65
- # { term: { spicy: 3 } },
66
- # ],
67
- # },
68
- # },
69
- # },
56
+ # {
57
+ # "query": {
58
+ # "bool": {
59
+ # "filter": [
60
+ # { "exists": { "field": ["address", "phone"] } },
61
+ # { "term": { "flavor": "vanilla" } },
62
+ # { "term":{ "scoops": 3 } }
63
+ # ],
64
+ # "must": [
65
+ # { "match": { "topping": "fudge" } }
66
+ # ]
67
+ # }
70
68
  # }
69
+ # }
71
70
  def count(opts = {})
72
71
  args = { body: body(opts) }
73
72
  @client.count(args)
74
73
  end
75
74
 
76
- # @return [Hash] with the actual result in the 'hits'['hits'] key.
75
+ # Search documents, filtered by options, aggregate on special
76
+ # aggregations keys.
77
+ #
78
+ # Supported aggregations (avg, cardinality, extended_stats, geo_bounds,
79
+ # geo_centroid, max min, percentiles, stats, sum, value_count) take
80
+ # a field name and are automatically named.
81
+ # @example
82
+ # opts = {
83
+ # query_string: 'flavor:vanilla AND cone:true',
84
+ # avg: "scoops",
85
+ # }
86
+ #
87
+ # Client.new.search(opts)
88
+ #
89
+ # # Tranforms opts into the following hash, passed to Elasticsearch:
90
+ # {
91
+ # "query": {
92
+ # "bool": {
93
+ # "filter":[],
94
+ # "must":[
95
+ # {
96
+ # "query_string": {
97
+ # "query":"flavor:vanilla AND cone:true"
98
+ # }
99
+ # }
100
+ # ]
101
+ # }
102
+ # },
103
+ # "aggs": {
104
+ # "avg-intelligence": {
105
+ # "avg": {
106
+ # "field":"scoops"
107
+ # }
108
+ # }
109
+ # }
110
+ # }
111
+ #
112
+ # @return [Hash] with the actual results in the <tt>'hits'['hits']</tt>
113
+ # key.
114
+ #
77
115
  # @param (see #count)
78
116
  # @option (see #count)
79
117
  # @option opts [Integer] :from
80
118
  # @option opts [Integer] :size
119
+ # @option opts [String] :avg
120
+ # Field name on which to apply the avg aggregation
121
+ # @option opts [String] :cardinality
122
+ # Field name on which to apply the cardinality aggregation
123
+ # @option opts [String] :extended_stats
124
+ # Field name on which to apply the extended_stats aggregation
125
+ # @option opts [String] :geo_bounds
126
+ # Field name on which to apply the geo_bounds aggregation
127
+ # @option opts [String] :geo_centroid
128
+ # Field name on which to apply the geo_centroid aggregation
129
+ # @option opts [String] :max
130
+ # Field name on which to apply the max aggregation
131
+ # @option opts [String] :min
132
+ # Field name on which to apply the min aggregation
133
+ # @option opts [String] :percentiles
134
+ # Field name on which to apply the percentiles aggregation
135
+ # @option opts [String] :stats
136
+ # Field name on which to apply the stats aggregation
137
+ # @option opts [String] :sum
138
+ # Field name on which to apply the sum aggregation
139
+ # @option opts [String] :value_count
140
+ # Field name on which to apply the value_count aggregation
81
141
  def search(opts)
82
142
  args = {
83
143
  from: opts[:from] ? opts[:from] : 0,
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.3' # :nodoc:
12
+ VERSION = '0.0.4' # :nodoc:
13
13
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: es_tractor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
- - oz
7
+ - utilum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
@@ -138,7 +138,7 @@ files:
138
138
  - test/helper.rb
139
139
  - test/test_client.rb
140
140
  - test/test_es_tractor.rb
141
- homepage: https://github.com/utilum/es_tractor
141
+ homepage: https://rubygems.org/gems/es_tractor
142
142
  licenses:
143
143
  - MIT
144
144
  metadata: {}