es_tractor 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +34 -26
- data/Rakefile +1 -1
- data/bin/console +2 -0
- data/lib/es_tractor/client.rb +78 -18
- data/lib/es_tractor.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c47c2590ee65edec76531a1d260adc2bcc9c670
|
4
|
+
data.tar.gz: a1cfa057e7d5b26586fb45c851e75b8fc851bc5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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://
|
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
|
-
*
|
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
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
data/bin/console
CHANGED
data/lib/es_tractor/client.rb
CHANGED
@@ -42,42 +42,102 @@ module EsTractor
|
|
42
42
|
#
|
43
43
|
# @example
|
44
44
|
# opts = {
|
45
|
-
# match: {
|
46
|
-
# exists: ['
|
45
|
+
# match: { topping: 'fudge' },
|
46
|
+
# exists: ['address', 'phone'],
|
47
47
|
# term: [
|
48
48
|
# { flavor: 'vanilla' },
|
49
|
-
# {
|
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
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
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
|
-
#
|
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
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.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
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://
|
141
|
+
homepage: https://rubygems.org/gems/es_tractor
|
142
142
|
licenses:
|
143
143
|
- MIT
|
144
144
|
metadata: {}
|