stretcher 1.16.3 → 1.17.0

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: e88325b35592832c59932c36dfccfa37fe03cb67
4
- data.tar.gz: d4d1fa224462b023ab743386b555f5cfd682146a
3
+ metadata.gz: 5af13ebaa51c4010121aa5c822e4a03e48b04a3c
4
+ data.tar.gz: 67731bd18d6203bc3cdfff0ef99de2fb12826d27
5
5
  SHA512:
6
- metadata.gz: 7278cc58d1d65a1ceac2f5b98e6c3fcd3b19d42c7ea904103bd0edbbf0ddc380fdf3dcdf6bf3a843d51291b030fcaa0f5ca22689fee3a4dde1a081b24b283c62
7
- data.tar.gz: 8c1f8c7d2b630b30d44e77824d080af805ad8fa334b45bd6aadc15c48a2f1bda2b23cc55ed6e605652135d0bd070a059c873449bbc5106b5e8f55a8c5dec21a5
6
+ metadata.gz: ff9ec72cdec4eb9f78274470ff4e79c32c1d7f1e24c945b7f0289bb1c22072e8e6727a6844699503cba38bf695204dc539b3910fea12efa11ed637a5f82ba1f7
7
+ data.tar.gz: 036f21bf4fbc7dd4a698a8148dbd81ba3fd7cdb579b2901ae3237d48c283334855b81529fa0cfc44cad3210f4180193d1b87ecda3b2502fd54b2bc2bdb7c2bed
data/README.md CHANGED
@@ -89,7 +89,7 @@ This README documents only part of stretcher's API. The full documentation for s
89
89
 
90
90
  ### Logging
91
91
 
92
- Pass in the the `:log_level` parameter to set logging verbosity. cURL statements are surfaced at the `:debug` log level. For instance:
92
+ Pass in the `:log_level` parameter to set logging verbosity. cURL statements are surfaced at the `:debug` log level. For instance:
93
93
 
94
94
  ```ruby
95
95
  Stretcher::Server.new('http://localhost:9200', :log_level => :debug)
@@ -116,10 +116,11 @@ Specs may be run with `rake spec`
116
116
  ## Contributors
117
117
 
118
118
  * [@andrewvc](https://github.com/andrewvc)
119
+ * [@cmaitchison](https://github.com/cmaitchison)
120
+ * [@danharvey](https://github.com/danharvey)
119
121
  * [@aq1018](https://github.com/aq1018)
120
122
  * [@akahn](https://github.com/akahn)
121
123
  * [@psynix](https://github.com/psynix)
122
- * [@cmaitchison](https://github.com/cmaitchison)
123
124
  * [@fmardini](https://github.com/fmardini)
124
125
  * [@chatgris](https://github.com/chatgris)
125
126
  * [@alpinegizmo](https://github.com/alpinegizmo)
@@ -38,5 +38,12 @@ module Stretcher
38
38
  req.body = query
39
39
  end
40
40
  end
41
+
42
+ def do_alias(alias_name_or_prefix)
43
+ request(:get, "_alias/#{alias_name_or_prefix}")
44
+ rescue Stretcher::RequestError::NotFound => e
45
+ return {} if e.http_response.status == 404
46
+ raise e
47
+ end
41
48
  end
42
49
  end
@@ -94,6 +94,11 @@ module Stretcher
94
94
  request :get, "_settings"
95
95
  end
96
96
 
97
+ # Update settings for this index
98
+ def update_settings(settings)
99
+ request :put, "_settings", nil, settings
100
+ end
101
+
97
102
  # Check if the index has been created on the remote server
98
103
  def exists?
99
104
  # Unless the exception is hit we know its a 2xx response
@@ -154,6 +159,11 @@ module Stretcher
154
159
  do_refresh
155
160
  end
156
161
 
162
+ # Perform an optimize on the index to merge and reduce the number of segments
163
+ def optimize(options=nil)
164
+ request(:post, "_optimize", options)
165
+ end
166
+
157
167
  # Full path to this index
158
168
  def path_uri(path="/")
159
169
  p = @server.path_uri("/#{name}")
@@ -185,6 +185,10 @@ module Stretcher
185
185
  end
186
186
  end
187
187
 
188
+ def get_alias(alias_name_or_prefix)
189
+ do_alias(alias_name_or_prefix)
190
+ end
191
+
188
192
  # Perform a refresh, making all indexed documents available
189
193
  def refresh
190
194
  do_refresh
@@ -192,7 +196,7 @@ module Stretcher
192
196
 
193
197
  # Full path to the server root dir
194
198
  def path_uri(path=nil)
195
- @uri.to_s + path.to_s
199
+ URI.join(@uri.to_s, path.to_s).to_s
196
200
  end
197
201
 
198
202
  # Handy way to query the server, returning *only* the body
@@ -1,3 +1,3 @@
1
1
  module Stretcher
2
- VERSION = "1.16.3"
2
+ VERSION = "1.17.0"
3
3
  end
@@ -220,4 +220,40 @@ describe Stretcher::Index do
220
220
  res = server.index(:does_not_exist).msearch([{:query => {:match_all => {}}}])
221
221
  }.should raise_exception(Stretcher::RequestError)
222
222
  end
223
+
224
+ describe "#update_settings" do
225
+ it "updates settings on the index" do
226
+ index.get_settings['foo']['settings']['index.number_of_replicas'].should eq("0")
227
+ index.update_settings("index.number_of_replicas" => "1")
228
+ index.get_settings['foo']['settings']['index.number_of_replicas'].should eq("1")
229
+ end
230
+ end
231
+
232
+ describe "#optimize" do
233
+ let(:request_url) { "http://localhost:9200/foo/_optimize" }
234
+
235
+ context "with no options" do
236
+ it "calls request for the correct endpoint with empty options" do
237
+ expect(index.server).to receive(:request).with(:post, request_url, nil, nil, {})
238
+ index.optimize
239
+ end
240
+
241
+ it "successfully runs the optimize command for the index" do
242
+ expect(index.optimize.ok).to be_true
243
+ end
244
+ end
245
+
246
+ context "with options" do
247
+ it "calls request for the correct endpoint with options passed" do
248
+ expect(index.server).to receive(:request).with(:post, request_url, {"max_num_segments" => 1}, nil, {})
249
+ index.optimize("max_num_segments" => 1)
250
+ end
251
+
252
+ it "successfully runs the optimize command for the index with the options passed" do
253
+ expect(index.optimize("max_num_segments" => 1).ok).to be_true
254
+ end
255
+ end
256
+
257
+ end
258
+
223
259
  end
@@ -1,7 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Stretcher::Server do
4
- let(:server) { Stretcher::Server.new(ES_URL, :logger => DEBUG_LOGGER) }
4
+ let(:server) do
5
+ server = Stretcher::Server.new(ES_URL, :logger => DEBUG_LOGGER)
6
+ i = server.index('foo')
7
+ i.delete rescue Stretcher::RequestError::NotFound
8
+ i.create
9
+ server
10
+ end
5
11
 
6
12
  it "should initialize cleanly" do
7
13
  server.class.should == Stretcher::Server
@@ -86,4 +92,50 @@ describe Stretcher::Server do
86
92
  server.analyze("Candles", :analyzer => :snowball)
87
93
  end
88
94
 
95
+ describe ".path_uri" do
96
+ context "uri contains trailing /" do
97
+ subject { Stretcher::Server.new("http://example.com/").path_uri("/foo") }
98
+ it { should eq ("http://example.com/foo") }
99
+ end
100
+
101
+ context "uri contains no trailing /" do
102
+ subject { Stretcher::Server.new("http://example.com").path_uri("/foo") }
103
+ it { should eq ("http://example.com/foo") }
104
+ end
105
+ end
106
+
107
+ describe "#get_alias" do
108
+ let(:request_url) { "_alias/bar" }
109
+ let(:http_response) { double("http_response") }
110
+ let(:exception) { Stretcher::RequestError::NotFound.new(http_response) }
111
+
112
+ it "sends a request to the correct endpoint with an alias that exists" do
113
+ expect(server).to receive(:request).with(:get, request_url) { :foo }
114
+ expect(server.get_alias("bar")).to eq(:foo)
115
+ end
116
+
117
+ it "sends a request to the correct endpoint with an alias that does not exist" do
118
+ expect(server).to receive(:request).with(:get, request_url).and_raise(exception)
119
+ expect(http_response).to receive(:status) { 404 }
120
+
121
+ expect(server.get_alias("bar")).to eq({})
122
+ end
123
+
124
+ it "sends a request to the correct endpoint and gets and error response" do
125
+ expect(server).to receive(:request).with(:get, request_url).and_raise(exception)
126
+ expect(http_response).to receive(:status) { 410 }
127
+
128
+ expect { server.get_alias("bar") }.to raise_error(exception)
129
+ end
130
+
131
+ it "should return an empty array if no aliases exist" do
132
+ expect(server.get_alias("bar")).to eq({})
133
+ end
134
+
135
+ it "should return a hash of the aliases if at least one exists" do
136
+ server.aliases(:actions => [{ :add => { :index => "foo", :alias => "bar" }}])
137
+ expect(server.get_alias("bar")).to eq({"foo" => {"aliases" => {"bar" => {}}}})
138
+ end
139
+ end
140
+
89
141
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stretcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.3
4
+ version: 1.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Cholakian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-26 00:00:00.000000000 Z
11
+ date: 2013-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday