elastomer-client 2.1.1 → 2.2.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: bf9d0a11b76b72579a70e136001f120d2e7b6ff6
4
- data.tar.gz: af19933f50777d3200c75b53078399e86fa82cca
3
+ metadata.gz: e0ff6e4010e81c9d42f412ac93cda3448bf3207f
4
+ data.tar.gz: da3742dd0d0724df7ab5b51b7ab2aa7ce9bca9e6
5
5
  SHA512:
6
- metadata.gz: 8c0f968a4fd443e7348ee39dd9dac33b4d7cffd51de59f8371b95227ccc0c8edeee54e22e9735bca1b6de6011d8fd9dbc1f65ee15e21eb39fa493efdd7f7acfa
7
- data.tar.gz: 1a7979eea4e56f99a95b0b8b99a58755bcdfc16cef073e1633db3ccc6ed07512dc1096eb8dc77bc0cab21b79c6805f92c3ce88ae8838c65a2027affb63b86844
6
+ metadata.gz: 251b9765f805d5f01dfd66f49e1899b80301ce2c0dfefce8e026657978335bf95ce2551acca5a3548a9c70098cd4f8da336bb674e671a57080d61b4346933af5
7
+ data.tar.gz: 2f397fe5deafd4bcdf17a8826715e2ab3f86870008ae0bfe63d1809aa45c49d1da53fb68f276f750327e5653bbf24d1ceeb250ce568392a7e355f8dfb304a0ba
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /coverage
8
8
  Gemfile.lock
9
9
  *.gem
10
+ tags
@@ -1,4 +1,9 @@
1
- ## 2.1.1 (2016-01-02)
1
+ ## 2.2.0 (2017-04-29)
2
+ - Added a `clear_scroll` API
3
+ - JSON timestamps include millisecodns by default
4
+ - Removing Fixnum usage
5
+
6
+ ## 2.1.1 (2016-09-02)
2
7
  - Bulk index only rejects documents larger than the maximum request size
3
8
 
4
9
  ## 2.1.0 (2016-01-02)
@@ -19,16 +19,14 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency "addressable", "~> 2.3"
22
+ spec.add_dependency "addressable", "~> 2.5"
23
23
  spec.add_dependency "faraday", "~> 0.8"
24
- spec.add_dependency "multi_json", "~> 1.7"
25
- spec.add_dependency "semantic", "~> 1.3"
24
+ spec.add_dependency "multi_json", "~> 1.12"
25
+ spec.add_dependency "semantic", "~> 1.6"
26
26
 
27
- spec.add_development_dependency "bundler", "~> 1.5"
27
+ spec.add_development_dependency "bundler", "~> 1.14"
28
28
  spec.add_development_dependency "activesupport", ">= 3.0"
29
- spec.add_development_dependency "minitest","~> 4.7"
30
- spec.add_development_dependency "webmock","~> 1.21"
29
+ spec.add_development_dependency "minitest", "~> 4.7"
30
+ spec.add_development_dependency "webmock", "~> 2.3"
31
31
  spec.add_development_dependency "rake"
32
- spec.add_development_dependency "overcommit"
33
- spec.add_development_dependency "rubocop"
34
32
  end
@@ -223,15 +223,19 @@ module Elastomer
223
223
  body = params.delete :body
224
224
  return if body.nil?
225
225
 
226
- case body
227
- when String
228
- body
229
- when Array
230
- body << nil unless body.last.nil?
231
- body.join "\n"
232
- else
233
- MultiJson.dump body
234
- end
226
+ body =
227
+ case body
228
+ when String
229
+ body
230
+ when Array
231
+ body << nil unless body.last.nil?
232
+ body.join "\n"
233
+ else
234
+ MultiJson.dump body
235
+ end
236
+
237
+ # Prevent excon from changing the encoding (see https://github.com/github/elastomer-client/issues/138)
238
+ body.freeze
235
239
  end
236
240
 
237
241
  # Internal: Apply path expansions to the `path` and append query
@@ -85,8 +85,9 @@ module Elastomer
85
85
 
86
86
  # Provide some nice errors for common Elasticsearch exceptions. These are
87
87
  # all subclasses of the more general RequestError
88
- IndexNotFoundError = Class.new RequestError
89
- QueryParsingError = Class.new RequestError
88
+ IndexNotFoundError = Class.new RequestError
89
+ QueryParsingError = Class.new RequestError
90
+ SearchContextMissing = Class.new RequestError
90
91
 
91
92
  ServerError.fatal = false
92
93
  TimeoutError.fatal = false
@@ -340,12 +340,18 @@ module Elastomer
340
340
  # can be retrieved with parameters.
341
341
  #
342
342
  # params - Parameters Hash
343
+ # :stats - a single stats value or an Array of stats values
344
+ #
345
+ # Examples
346
+ #
347
+ # stats(stats: "docs")
348
+ # stats(stats: %w[flush merge])
343
349
  #
344
350
  # See https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-stats.html
345
351
  #
346
352
  # Returns the response body as a Hash
347
353
  def stats( params = {} )
348
- response = client.get "{/index}/_stats", update_params(params, :action => "index.stats")
354
+ response = client.get "{/index}/_stats{/stats}", update_params(params, :action => "index.stats")
349
355
  response.body
350
356
  end
351
357
 
@@ -53,7 +53,7 @@ module Elastomer
53
53
  # See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html
54
54
  #
55
55
  # opts - Options Hash
56
- # :query - the query to scroll as a Hash or JSON encoded String
56
+ # :body - the query to scroll as a Hash or JSON encoded String
57
57
  # :index - the name of the index to search
58
58
  # :type - the document type to search
59
59
  # :scroll - the keep alive time of the scrolling request (5 minutes by default)
@@ -62,7 +62,7 @@ module Elastomer
62
62
  #
63
63
  # Examples
64
64
  #
65
- # h = client.start_scroll('{"query":{"match_all":{}},"sort":{"created":"desc"}}', :index => 'test')
65
+ # h = client.start_scroll(:body => '{"query":{"match_all":{}},"sort":{"created":"desc"}}', :index => 'test')
66
66
  # scroll_id = h['_scroll_id']
67
67
  # h['hits']['hits'].each { |doc| ... }
68
68
  #
@@ -87,7 +87,7 @@ module Elastomer
87
87
  #
88
88
  # Examples
89
89
  #
90
- # scroll_id = client.start_scroll('{"query":{"match_all":{}}}', :index => 'test')['_scroll_id']
90
+ # scroll_id = client.start_scroll(:body => '{"query":{"match_all":{}}}', :index => 'test')['_scroll_id']
91
91
  #
92
92
  # h = client.continue_scroll scroll_id # scroll to get the next set of results
93
93
  # scroll_id = h['_scroll_id'] # and store the scroll_id to use later
@@ -101,6 +101,24 @@ module Elastomer
101
101
  def continue_scroll( scroll_id, scroll = "5m" )
102
102
  response = get "/_search/scroll", :body => scroll_id, :scroll => scroll, :action => "search.scroll"
103
103
  response.body
104
+ rescue RequestError => err
105
+ if err.error && err.error["caused_by"]["type"] == "search_context_missing_exception" \
106
+ || err.message =~ /SearchContextMissingException/
107
+ raise SearchContextMissing, "No search context found for scroll ID #{scroll_id.inspect}"
108
+ else
109
+ raise err
110
+ end
111
+ end
112
+
113
+ # Delete one or more scroll IDs.
114
+ # see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html#_clear_scroll_api
115
+ #
116
+ # scroll_id - One or more scroll IDs
117
+ #
118
+ # Returns the response body as a Hash.
119
+ def clear_scroll( scroll_ids )
120
+ response = delete "/_search/scroll", :body => {scroll_id: Array(scroll_ids)}, :action => "search.clear_scroll"
121
+ response.body
104
122
  end
105
123
 
106
124
  DEFAULT_OPTS = {
@@ -24,8 +24,9 @@ module Elastomer
24
24
  attr_reader :client, :name
25
25
 
26
26
  # Returns true if the template already exists on the cluster.
27
- def exists?
28
- client.cluster.templates.key? name
27
+ def exists?( params = {} )
28
+ response = client.head "/_template/{template}", update_params(params, action: "template.exists")
29
+ response.success?
29
30
  end
30
31
  alias_method :exist?, :exists?
31
32
 
@@ -2,6 +2,6 @@ require "time"
2
2
 
3
3
  class Time
4
4
  def to_json(ignore = nil)
5
- %Q["#{self.iso8601}"]
5
+ %Q["#{self.iso8601(3)}"]
6
6
  end
7
7
  end
@@ -1,5 +1,5 @@
1
1
  module Elastomer
2
- VERSION = "2.1.1"
2
+ VERSION = "2.2.0"
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -7,5 +7,3 @@ if bundle check 1>/dev/null 2>&1; then
7
7
  else
8
8
  exec bundle install --binstubs --path vendor/gems "$@"
9
9
  fi
10
-
11
- overcommit --install
@@ -85,7 +85,7 @@ describe Elastomer::Client::Bulk do
85
85
  end
86
86
  items = h["items"]
87
87
 
88
- assert_instance_of Fixnum, h["took"]
88
+ assert_kind_of Integer, h["took"]
89
89
 
90
90
  assert_bulk_index h["items"].first
91
91
  assert_bulk_create h["items"].last
@@ -130,7 +130,7 @@ describe Elastomer::Client::Bulk do
130
130
  end
131
131
  items = h["items"]
132
132
 
133
- assert_instance_of Fixnum, h["took"]
133
+ assert_kind_of Integer, h["took"]
134
134
 
135
135
  assert_bulk_index h["items"].first
136
136
  assert_bulk_create h["items"].last
@@ -259,7 +259,7 @@ describe Elastomer::Client::Bulk do
259
259
  b.index document, params
260
260
  end
261
261
 
262
- assert_instance_of Fixnum, response["took"]
262
+ assert_kind_of Integer, response["took"]
263
263
 
264
264
  items = response["items"]
265
265
  assert_bulk_index(items[0])
@@ -276,7 +276,7 @@ describe Elastomer::Client::Bulk do
276
276
  b.index doc2, { "id" => "bar", "type" => "tweet" }
277
277
  end
278
278
 
279
- assert_instance_of Fixnum, response["took"]
279
+ assert_kind_of Integer, response["took"]
280
280
 
281
281
  items = response["items"]
282
282
  assert_bulk_index(items[0])
@@ -294,7 +294,7 @@ describe Elastomer::Client::Bulk do
294
294
  b.index document, params
295
295
  end
296
296
 
297
- assert_instance_of Fixnum, response["took"]
297
+ assert_kind_of Integer, response["took"]
298
298
 
299
299
  items = response["items"]
300
300
  assert_bulk_index(items[0])
@@ -311,7 +311,7 @@ describe Elastomer::Client::Bulk do
311
311
  b.index document, params
312
312
  end
313
313
 
314
- assert_instance_of Fixnum, response["took"]
314
+ assert_kind_of Integer, response["took"]
315
315
 
316
316
  items = response["items"]
317
317
  assert_bulk_index(items[0])
@@ -93,6 +93,20 @@ describe Elastomer::Client::Scroller do
93
93
  assert_equal 1, counts["book"]
94
94
  end
95
95
 
96
+ it "clears one or more scroll IDs" do
97
+ h = $client.start_scroll \
98
+ body: {query: {match_all: {}}},
99
+ index: @index.name,
100
+ type: "tweet",
101
+ scroll: "1m",
102
+ size: 10
103
+
104
+ refute_nil h["_scroll_id"], "response is missing a scroll ID"
105
+
106
+ response = $client.clear_scroll(h["_scroll_id"])
107
+ assert_empty response
108
+ end
109
+
96
110
  def populate!
97
111
  h = @index.bulk do |b|
98
112
  50.times { |num|
@@ -97,6 +97,20 @@ describe Elastomer::Client do
97
97
  body = $client.extract_body :body => {:query => {:match_all => {}}}
98
98
  assert_equal '{"query":{"match_all":{}}}', body
99
99
  end
100
+
101
+ it "returns frozen strings" do
102
+ body = $client.extract_body :body => '{"query":{"match_all":{}}}'
103
+ assert_equal '{"query":{"match_all":{}}}', body
104
+ assert body.frozen?, "the body string should be frozen"
105
+
106
+ body = $client.extract_body :body => %w[foo bar baz]
107
+ assert_equal "foo\nbar\nbaz\n", body
108
+ assert body.frozen?, "Array body strings should be frozen"
109
+
110
+ body = $client.extract_body :body => {:query => {:match_all => {}}}
111
+ assert_equal '{"query":{"match_all":{}}}', body
112
+ assert body.frozen?, "JSON encoded body strings should be frozen"
113
+ end
100
114
  end
101
115
 
102
116
  describe "when validating parameters" do
@@ -31,7 +31,7 @@ describe "JSON conversions for Time" do
31
31
 
32
32
  it "generates ISO8601 formatted time strings" do
33
33
  time = Time.utc(2013, 5, 3, 10, 1, 31)
34
- assert_equal '"2013-05-03T10:01:31Z"', MultiJson.encode(time)
34
+ assert_equal '"2013-05-03T10:01:31.000Z"', MultiJson.encode(time)
35
35
  end
36
36
 
37
37
  it "indexes time fields" do
@@ -41,6 +41,6 @@ describe "JSON conversions for Time" do
41
41
  assert_created(h)
42
42
 
43
43
  doc = @docs.get(:type => "doc1", :id => h["_id"])
44
- assert_equal "2013-05-03T10:01:31Z", doc["_source"]["created_at"]
44
+ assert_equal "2013-05-03T10:01:31.000Z", doc["_source"]["created_at"]
45
45
  end
46
46
  end
@@ -25,7 +25,7 @@ require "elastomer/client"
25
25
  # we are going to use the same client instance everywhere!
26
26
  # the client should always be stateless
27
27
  $client_params = {
28
- :port => ENV["BOXEN_ELASTICSEARCH_PORT"] || 9200,
28
+ :port => 9200,
29
29
  :read_timeout => 10,
30
30
  :open_timeout => 1,
31
31
  :opaque_id => false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastomer-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Pease
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-09-02 00:00:00.000000000 Z
12
+ date: 2017-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '2.3'
20
+ version: '2.5'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '2.3'
27
+ version: '2.5'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: faraday
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -45,42 +45,42 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '1.7'
48
+ version: '1.12'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '1.7'
55
+ version: '1.12'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: semantic
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '1.3'
62
+ version: '1.6'
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '1.3'
69
+ version: '1.6'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: bundler
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '1.5'
76
+ version: '1.14'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '1.5'
83
+ version: '1.14'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: activesupport
86
86
  requirement: !ruby/object:Gem::Requirement
@@ -115,14 +115,14 @@ dependencies:
115
115
  requirements:
116
116
  - - "~>"
117
117
  - !ruby/object:Gem::Version
118
- version: '1.21'
118
+ version: '2.3'
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
123
  - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: '1.21'
125
+ version: '2.3'
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: rake
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -137,34 +137,6 @@ dependencies:
137
137
  - - ">="
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
- - !ruby/object:Gem::Dependency
141
- name: overcommit
142
- requirement: !ruby/object:Gem::Requirement
143
- requirements:
144
- - - ">="
145
- - !ruby/object:Gem::Version
146
- version: '0'
147
- type: :development
148
- prerelease: false
149
- version_requirements: !ruby/object:Gem::Requirement
150
- requirements:
151
- - - ">="
152
- - !ruby/object:Gem::Version
153
- version: '0'
154
- - !ruby/object:Gem::Dependency
155
- name: rubocop
156
- requirement: !ruby/object:Gem::Requirement
157
- requirements:
158
- - - ">="
159
- - !ruby/object:Gem::Version
160
- version: '0'
161
- type: :development
162
- prerelease: false
163
- version_requirements: !ruby/object:Gem::Requirement
164
- requirements:
165
- - - ">="
166
- - !ruby/object:Gem::Version
167
- version: '0'
168
140
  description: |-
169
141
  Elastomer is a low level API client for the
170
142
  Elasticsearch HTTP interface.
@@ -268,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
268
240
  version: '0'
269
241
  requirements: []
270
242
  rubyforge_project:
271
- rubygems_version: 2.2.3
243
+ rubygems_version: 2.6.11
272
244
  signing_key:
273
245
  specification_version: 4
274
246
  summary: A library for interacting with Elasticsearch