stretcher 1.11.1 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.coveralls.yml +1 -0
- data/README.md +7 -4
- data/lib/stretcher.rb +2 -1
- data/lib/stretcher/server.rb +39 -16
- data/lib/stretcher/version.rb +1 -1
- data/spec/lib/stretcher_server_spec.rb +14 -1
- data/spec/spec_helper.rb +3 -0
- data/stretcher.gemspec +2 -1
- metadata +24 -7
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Stretcher
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/stretcher.png)](http://badge.fury.io/rb/stretcher)
|
3
4
|
[![Build Status](https://travis-ci.org/PoseBiz/stretcher.png?branch=master)](https://travis-ci.org/PoseBiz/stretcher)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/PoseBiz/stretcher.png)](https://codeclimate.com/github/PoseBiz/stretcher)
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/PoseBiz/stretcher/badge.png)](https://coveralls.io/r/PoseBiz/stretcher)
|
4
7
|
|
5
8
|
A concise, fast ElasticSearch client designed to reflect the actual elastic search API as closely as possible. Elastic search's API is complex, and mostly documented on the Elastic Search Guide. This client tries to stay out of your way more than others making advanced techniques easier to implement, and making debugging Elastic Search's sometimes cryptic errors easier.
|
6
9
|
|
@@ -25,7 +28,7 @@ gem 'stretcher'
|
|
25
28
|
|
26
29
|
### Basic Usage
|
27
30
|
|
28
|
-
```ruby
|
31
|
+
```ruby
|
29
32
|
# First Create a server
|
30
33
|
server = Stretcher::Server.new('http://localhost:9200')
|
31
34
|
# Delete an index (in case you already have this one)
|
@@ -54,13 +57,13 @@ res.raw # => #<Hashie::Mash ...> Raw JSON from the search
|
|
54
57
|
Stretcher::Server.with_server('http://localhost:9200') {|srv|
|
55
58
|
srv.index(:foo) {|idx|
|
56
59
|
idx.type(:tweet) {|t| {exists: t.exists?, mapping: t.get_mapping} }
|
57
|
-
}
|
60
|
+
}
|
58
61
|
}
|
59
62
|
# => {:exists=>true, :mapping=>#<Hashie::Mash tweet=...>}
|
60
63
|
```
|
61
64
|
|
62
65
|
### Multi Search
|
63
|
-
|
66
|
+
|
64
67
|
```ruby
|
65
68
|
# Within a single index
|
66
69
|
server.index(:foo).msearch([{query: {match_all: {}}}])
|
@@ -71,7 +74,7 @@ server.msearch([{index: :foo}, {query: {match_all: {}}}])
|
|
71
74
|
```
|
72
75
|
|
73
76
|
### Bulk Indexing
|
74
|
-
|
77
|
+
|
75
78
|
```ruby
|
76
79
|
docs = [{"_type" => "tweet", "_id" => 91011, "text" => "Bulked"}]
|
77
80
|
server.index(:foo).bulk_index(docs)
|
data/lib/stretcher.rb
CHANGED
data/lib/stretcher/server.rb
CHANGED
@@ -15,7 +15,17 @@ module Stretcher
|
|
15
15
|
# The options hash takes an optional instance of Logger under :logger.
|
16
16
|
#
|
17
17
|
# server = Stretcher::Server.new('http://localhost:9200')
|
18
|
+
#
|
19
|
+
# The default implementation here uses the net_http_persistent adapter
|
20
|
+
# for faraday. If you would like to use a different HTTP library, or alter
|
21
|
+
# other faraday config settings you may specify an optional :faraday_configurator
|
22
|
+
# argument, with a Proc as a value. This will be called once with the faraday builder.
|
23
|
+
#
|
24
|
+
# For instance:
|
25
|
+
# configurator = proc {|builder| builder.adapter :typhoeus
|
26
|
+
# Stretcher::Server.new('http://localhost:9200', :faraday_configurator => configurator)
|
18
27
|
def initialize(uri='http://localhost:9200', options={})
|
28
|
+
@request_mtx = Mutex.new
|
19
29
|
@uri = uri
|
20
30
|
|
21
31
|
@http = Faraday.new(:url => @uri) do |builder|
|
@@ -24,10 +34,14 @@ module Stretcher
|
|
24
34
|
|
25
35
|
builder.request :json
|
26
36
|
|
27
|
-
builder.
|
37
|
+
builder.options[:read_timeout] = 4 || options[:read_timeout]
|
38
|
+
builder.options[:open_timeout] = 2 || options[:open_timeout]
|
28
39
|
|
29
|
-
|
30
|
-
|
40
|
+
if faraday_configurator = options[:faraday_configurator]
|
41
|
+
faraday_configurator.call(builder)
|
42
|
+
else
|
43
|
+
builder.adapter :excon
|
44
|
+
end
|
31
45
|
end
|
32
46
|
|
33
47
|
uri_components = URI.parse(@uri)
|
@@ -124,14 +138,18 @@ module Stretcher
|
|
124
138
|
req.body = text
|
125
139
|
end
|
126
140
|
end
|
127
|
-
|
141
|
+
|
128
142
|
# Implements the Aliases API
|
129
|
-
# Ex:
|
143
|
+
# Ex:
|
130
144
|
# server.aliases({actions: {add: {index: :my_index, alias: :my_alias}}})
|
131
145
|
# as per: http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases.html
|
132
|
-
def aliases(body)
|
133
|
-
|
134
|
-
|
146
|
+
def aliases(body=nil)
|
147
|
+
if body
|
148
|
+
request(:post, path_uri("/_aliases")) do |req|
|
149
|
+
req.body = body
|
150
|
+
end
|
151
|
+
else
|
152
|
+
request(:get, path_uri("/_aliases"))
|
135
153
|
end
|
136
154
|
end
|
137
155
|
|
@@ -149,15 +167,20 @@ module Stretcher
|
|
149
167
|
# Will raise an exception when the status is not in the 2xx range
|
150
168
|
def request(method, url=nil, query_opts=nil, *args, &block)
|
151
169
|
logger.info { "Stretcher: Issuing Request #{method.to_s.upcase}, #{Util.qurl(url,query_opts)}" }
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
170
|
+
|
171
|
+
# Our default client is threadsafe, but some others might not be
|
172
|
+
res = nil
|
173
|
+
@request_mtx.synchronize {
|
174
|
+
res = if block
|
175
|
+
http.send(method, url, query_opts, *args) do |req|
|
176
|
+
# Elastic search does mostly deal with JSON
|
177
|
+
req.headers["Content-Type"] = 'application/json'
|
178
|
+
block.call(req)
|
179
|
+
end
|
180
|
+
else
|
181
|
+
http.send(method, url, query_opts, *args)
|
157
182
|
end
|
158
|
-
|
159
|
-
http.send(method, url, query_opts, *args)
|
160
|
-
end
|
183
|
+
}
|
161
184
|
|
162
185
|
if res.status >= 200 && res.status <= 299
|
163
186
|
res.body
|
data/lib/stretcher/version.rb
CHANGED
@@ -17,6 +17,18 @@ describe Stretcher::Server do
|
|
17
17
|
exposed.class.should == Stretcher::Server
|
18
18
|
end
|
19
19
|
|
20
|
+
it "should properly set alternate faraday options if requested" do
|
21
|
+
# This spec could work better, but it's hard to reach into the
|
22
|
+
# guts of faraday
|
23
|
+
conf_called = false
|
24
|
+
configurator = lambda {|builder|
|
25
|
+
builder.adapter :net_http
|
26
|
+
conf_called = true
|
27
|
+
}
|
28
|
+
srv = Stretcher::Server.new(ES_URL, {:faraday_configurator => configurator})
|
29
|
+
conf_called.should be_true
|
30
|
+
end
|
31
|
+
|
20
32
|
it "should properly return that our server is up" do
|
21
33
|
server.up?.should be_true
|
22
34
|
end
|
@@ -29,11 +41,12 @@ describe Stretcher::Server do
|
|
29
41
|
# Tear down any leftovers from previous runs
|
30
42
|
server.aliases(:actions => [{:remove => {:alias => :foo_alias}}]) if server.index(:foo_alias).exists?
|
31
43
|
server.index(:foo).delete if server.index(:foo).exists?
|
32
|
-
|
33
44
|
server.index(:foo).create
|
34
45
|
server.aliases(:actions => [{:add => {:index => :foo, :alias => :foo_alias}}])
|
35
46
|
|
36
47
|
server.index(:foo_alias).get_settings.should == server.index(:foo).get_settings
|
48
|
+
|
49
|
+
server.aliases[:foo][:aliases].keys.should include 'foo_alias'
|
37
50
|
end
|
38
51
|
|
39
52
|
it "should check the status w/o error" do
|
data/spec/spec_helper.rb
CHANGED
data/stretcher.gemspec
CHANGED
@@ -28,10 +28,11 @@ Gem::Specification.new do |gem|
|
|
28
28
|
|
29
29
|
gem.add_dependency('faraday', '~> 0.8')
|
30
30
|
gem.add_dependency('faraday_middleware', '~> 0.9.0')
|
31
|
-
gem.add_dependency('
|
31
|
+
gem.add_dependency('excon', '>= 0.16')
|
32
32
|
gem.add_dependency('hashie', '~> 1.2.0')
|
33
33
|
|
34
34
|
gem.add_development_dependency 'rspec', '>= 2.5.0'
|
35
|
+
gem.add_development_dependency 'coveralls'
|
35
36
|
gem.add_development_dependency 'simplecov'
|
36
37
|
gem.add_development_dependency 'vcr'
|
37
38
|
gem.add_development_dependency 'rake'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stretcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.12.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -44,21 +44,21 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 0.9.0
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: excon
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '0.16'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0.16'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: hashie
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,6 +91,22 @@ dependencies:
|
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: 2.5.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: coveralls
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
94
110
|
- !ruby/object:Gem::Dependency
|
95
111
|
name: simplecov
|
96
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,6 +162,7 @@ executables: []
|
|
146
162
|
extensions: []
|
147
163
|
extra_rdoc_files: []
|
148
164
|
files:
|
165
|
+
- .coveralls.yml
|
149
166
|
- .gitignore
|
150
167
|
- .travis.yml
|
151
168
|
- Gemfile
|