elastomer-client 0.5.1 → 0.6.0

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: eee472ee555f628e95e3dd97d76ead36bc509e41
4
- data.tar.gz: a56d61d1c97b089af9170a1e662b835b6c6def50
3
+ metadata.gz: 20de9fda77111f1c5d50ccbbb63dd8b3316f7149
4
+ data.tar.gz: 97b970b60153c6069c44d866b00c08ba0542ae24
5
5
  SHA512:
6
- metadata.gz: 62ec42794c0799c52152e5b2ce6962b241c6dde67d46d402466957c5582c8b2ffd0b4cde9ddbdd355c71516f87bc60fba59f470b735b7dfb28c34731a2e35c7f
7
- data.tar.gz: 837d5438ca92b8d4b7296a2086504fffb51b01daa39003fbbb2b9d2b5407ddb30a76846fdaf53c552c6a6148b0a57270ca37735275b02dde809579d7cce07c9e
6
+ metadata.gz: 25dd4d57d43c60e279eaec42708d0ba8f12ad3d085baa64d9b68c489e31f5f152e54b5663fad14afe1c459245e7ca9237082fe41d834a8126be3c09f3d311899
7
+ data.tar.gz: 751eeeb151a1e582903b84f6383de2f7ff47f39db86afeb582fed185775b6881b915ddaf80c3326930f988bf21d558eb3f66dae82f26b018d4b9c641b64d6b50
@@ -1,3 +1,10 @@
1
+ ## 0.6.0 (2015-09-11)
2
+ - Support all URL parameters when using `Client.#scroll`
3
+ - BREAKING: Moved some `Scroller` reader methods into `Scroller.opts`
4
+
5
+ ## 0.5.1 (2015-04-03)
6
+ - Add response body to notification payload
7
+
1
8
  ## 0.5.0 (2015-01-21)
2
9
  - BREAKING: rename action.available notification to action.ping
3
10
  - Index Component
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require "bundler/gem_tasks"
3
3
  require 'rake/testtask'
4
4
 
5
5
  Rake::TestTask.new do |t|
6
- t.pattern = "test/**/*_test.rb"
6
+ t.test_files = FileList["test/**/*_test.rb"]
7
7
  end
8
8
 
9
9
  task :default => :test
@@ -84,6 +84,15 @@ module Elastomer
84
84
  response.body
85
85
  end
86
86
 
87
+ # Returns `true` if there items in the pending task list. Returns `false`
88
+ # if the pending task list is empty. Returns `nil` if the response body
89
+ # does not contain the "tasks" field.
90
+ def pending_tasks?
91
+ hash = pending_tasks
92
+ return nil unless hash.key? "tasks"
93
+ hash["tasks"].length > 0
94
+ end
95
+
87
96
  # Cluster wide settings that have been modified via the update API.
88
97
  #
89
98
  # params - Parameters Hash
@@ -101,6 +101,13 @@ module Elastomer
101
101
  response.body
102
102
  end
103
103
 
104
+ DEFAULT_OPTS = {
105
+ :index => nil,
106
+ :type => nil,
107
+ :scroll => '5m',
108
+ :size => 50,
109
+ }.freeze
110
+
104
111
  class Scroller
105
112
  # Create a new scroller that can be used to iterate over all the documents
106
113
  # returned by the `query`. The Scroller supports both the 'scan' and the
@@ -128,19 +135,14 @@ module Elastomer
128
135
  #
129
136
  def initialize( client, query, opts = {} )
130
137
  @client = client
131
- @query = query
132
138
 
133
- @index = opts.fetch(:index, nil)
134
- @type = opts.fetch(:type, nil)
135
- @scroll = opts.fetch(:scroll, '5m')
136
- @size = opts.fetch(:size, 50)
137
- @search_type = opts.fetch(:search_type, nil)
139
+ @opts = DEFAULT_OPTS.merge({ :body => query }).merge(opts)
138
140
 
139
141
  @scroll_id = nil
140
142
  @offset = 0
141
143
  end
142
144
 
143
- attr_reader :client, :query, :index, :type, :scroll, :size, :search_type, :scroll_id
145
+ attr_reader :client, :query, :scroll_id
144
146
 
145
147
  # Iterate over all the search results from the scan query.
146
148
  #
@@ -203,33 +205,19 @@ module Elastomer
203
205
  # Returns the response body as a Hash.
204
206
  def do_scroll
205
207
  if scroll_id.nil?
206
- body = client.start_scroll(scroll_opts)
208
+ body = client.start_scroll(@opts)
207
209
  if body['hits']['hits'].empty?
208
210
  @scroll_id = body['_scroll_id']
209
211
  return do_scroll
210
212
  end
211
213
  else
212
- body = client.continue_scroll(scroll_id, scroll)
214
+ body = client.continue_scroll(scroll_id, @opts[:scroll])
213
215
  end
214
216
 
215
217
  @scroll_id = body['_scroll_id']
216
218
  body
217
219
  end
218
220
 
219
- # Internal: Returns the options Hash that should be passed to the initial
220
- # `Client#start_scroll` method call.
221
- def scroll_opts
222
- hash = {
223
- :scroll => scroll,
224
- :size => size,
225
- :index => index,
226
- :type => type,
227
- :body => query
228
- }
229
- hash[:search_type] = search_type unless search_type.nil?
230
- hash
231
- end
232
-
233
221
  end # Scroller
234
222
  end # Client
235
223
  end # Elastomer
@@ -1,5 +1,5 @@
1
1
  module Elastomer
2
- VERSION = '0.5.1'
2
+ VERSION = '0.6.0'
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -12,11 +12,6 @@ PATH="$(pwd)/bin:$(pwd)/script:/usr/share/rbenv/shims:$PATH"
12
12
  git log -n 1 || true
13
13
  echo
14
14
 
15
- # Create a snapshot dir and make it world writable
16
- export SNAPSHOT_DIR=/tmp/elastomer-client-snapshot-test
17
- mkdir -p $SNAPSHOT_DIR
18
- chmod a+rw $SNAPSHOT_DIR
19
-
20
15
  result=0
21
16
 
22
17
  export RBENV_VERSION="2.1.1-github"
@@ -2,5 +2,5 @@
2
2
  set -e
3
3
  cd "$(dirname "$0")/.."
4
4
 
5
- fn=${1:-"test/**/*_test.rb"}
5
+ fn=${1:-"test/**/*_test.rb test/*_test.rb"}
6
6
  bundle exec testrb -Itest $fn $@
@@ -127,6 +127,10 @@ describe Elastomer::Client::Index do
127
127
  end
128
128
 
129
129
  it 'updates document mappings' do
130
+ unless es_version_supports_update_mapping_with__all_disabled?
131
+ skip "Mapping Update API is broken in this ES version."
132
+ end
133
+
130
134
  @index.create(
131
135
  :mappings => {
132
136
  :doco => {
@@ -154,6 +158,10 @@ describe Elastomer::Client::Index do
154
158
  end
155
159
 
156
160
  it 'updates document mappings with .put_mapping' do
161
+ unless es_version_supports_update_mapping_with__all_disabled?
162
+ skip "Mapping Update API is broken in this ES version."
163
+ end
164
+
157
165
  @index.create(
158
166
  :mappings => {
159
167
  :doco => {
@@ -5,6 +5,10 @@ describe Elastomer::Client::Repository do
5
5
  if es_version_1_x?
6
6
 
7
7
  before do
8
+ if !run_snapshot_tests?
9
+ skip "To enable snapshot tests, add a path.repo setting to your elasticsearch.yml file."
10
+ end
11
+
8
12
  @name = 'elastomer-repository-test'
9
13
  @repo = $client.repository(@name)
10
14
  end
@@ -83,6 +83,16 @@ describe Elastomer::Client::Scroller do
83
83
  assert_equal expected, tweets
84
84
  end
85
85
 
86
+ it 'propagates URL query strings' do
87
+ scan = @index.scan(nil, { :q => 'author:pea53 || title:17' })
88
+
89
+ counts = {'tweet' => 0, 'book' => 0}
90
+ scan.each_document { |h| counts[h['_type']] += 1 }
91
+
92
+ assert_equal 50, counts['tweet']
93
+ assert_equal 1, counts['book']
94
+ end
95
+
86
96
  def populate!
87
97
  h = @index.bulk do |b|
88
98
  50.times { |num|
@@ -4,13 +4,17 @@ require File.expand_path('../../test_helper', __FILE__)
4
4
  describe Elastomer::Client::Snapshot do
5
5
  if es_version_1_x?
6
6
  before do
7
+ if !run_snapshot_tests?
8
+ skip "To enable snapshot tests, add a path.repo setting to your elasticsearch.yml file."
9
+ end
10
+
7
11
  @index_name = 'elastomer-snapshot-test-index'
8
12
  @index = $client.index(@index_name)
9
13
  @name = 'elastomer-test'
10
14
  end
11
15
 
12
16
  after do
13
- @index.delete if @index.exists?
17
+ @index.delete if @index && @index.exists?
14
18
  end
15
19
 
16
20
  it 'determines if a snapshot exists' do
@@ -99,7 +103,7 @@ describe Elastomer::Client::Snapshot do
99
103
  end
100
104
 
101
105
  after do
102
- @restored_index.delete if @restored_index.exists?
106
+ @restored_index.delete if @restored_index && @restored_index.exists?
103
107
  end
104
108
 
105
109
  it 'restores snapshots with options' do
@@ -11,8 +11,6 @@ if ENV['COVERAGE'] == 'true'
11
11
  end
12
12
  end
13
13
 
14
- ENV['SNAPSHOT_DIR'] ||= '/tmp/elastomer-client-snapshot-test'
15
-
16
14
  require 'minitest/spec'
17
15
  require 'minitest/autorun'
18
16
 
@@ -92,12 +90,12 @@ def es_version_1_x?
92
90
  end
93
91
 
94
92
  # Elasticsearch 1.4 changed the response body for interacting with index
95
- # alaises. If an index does not contain any aliases, then an "alises" key is no
96
- # longer returned in the resopsne.
93
+ # aliases. If an index does not contain any aliases, then an "aliases" key is no
94
+ # longer returned in the response.
97
95
  #
98
- # Reeturns `true` if the response contains an "alises" key.
96
+ # Returns `true` if the response contains an "aliases" key.
99
97
  def es_version_always_returns_aliases?
100
- $client.semantic_version <= '1.4.0' ||
98
+ $client.semantic_version < '1.4.0' ||
101
99
  $client.semantic_version >= '1.4.3'
102
100
  end
103
101
 
@@ -113,8 +111,40 @@ def es_version_supports_gateway_snapshots?
113
111
  $client.semantic_version <= '1.2.0'
114
112
  end
115
113
 
114
+ # Elasticsearch 1.4.0 had a bug in its handling of the Mapping API where it
115
+ # would not accept an Update request if the index had been created with the
116
+ # _all field set to disabled. This bug was fixed in 1.4.1.
117
+ #
118
+ # See: https://github.com/elastic/elasticsearch/pull/8426
119
+ def es_version_supports_update_mapping_with__all_disabled?
120
+ $client.semantic_version != '1.4.0'
121
+ end
122
+
123
+ # Elasticsearch 1.6 requires the repo.path setting when creating
124
+ # FS repositories.
125
+ def es_version_requires_repo_path?
126
+ $client.semantic_version >= '1.6.0'
127
+ end
128
+
129
+ def run_snapshot_tests?
130
+ unless defined? $run_snapshot_tests
131
+ begin
132
+ create_repo("elastomer-client-snapshot-test")
133
+ $run_snapshot_tests = true
134
+ rescue Elastomer::Client::Error => e
135
+ puts "Could not create a snapshot repo. Snapshot tests will be disabled."
136
+ puts "To enable snapshot tests, add a path.repo setting to your elasticsearch.yml file."
137
+ $run_snapshot_tests = false
138
+ ensure
139
+ delete_repo("elastomer-client-snapshot-test")
140
+ end
141
+ end
142
+ $run_snapshot_tests
143
+ end
144
+
116
145
  def create_repo(name, settings = {})
117
- default_settings = {:type => 'fs', :settings => {:location => ENV['SNAPSHOT_DIR']}}
146
+ location = File.join(*[ENV['SNAPSHOT_DIR'], name].compact)
147
+ default_settings = {:type => 'fs', :settings => {:location => location}}
118
148
  $client.repository(name).create(default_settings.merge(settings))
119
149
  end
120
150
 
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: 0.5.1
4
+ version: 0.6.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: 2015-04-03 00:00:00.000000000 Z
12
+ date: 2015-09-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -217,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
217
  version: '0'
218
218
  requirements: []
219
219
  rubyforge_project:
220
- rubygems_version: 2.2.2
220
+ rubygems_version: 2.2.3
221
221
  signing_key:
222
222
  specification_version: 4
223
223
  summary: A library for interacting with Elasticsearch