elastictastic 0.10.8 → 0.10.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -110,9 +110,9 @@ module Elastictastic
110
110
  # in the default index.
111
111
  #
112
112
 
113
- delegate :find, :destroy_all, :sync_mapping, :inspect, :find_each,
114
- :find_in_batches, :first, :count, :empty?, :any?, :all,
115
- :query, :filter, :from, :size, :sort, :highlight, :fields,
113
+ delegate :find, :destroy, :destroy_all, :sync_mapping, :inspect,
114
+ :find_each, :find_in_batches, :first, :count, :empty?, :any?,
115
+ :all, :query, :filter, :from, :size, :sort, :highlight, :fields,
116
116
  :script_fields, :preference, :facets, :routing,
117
117
  :to => :current_scope
118
118
 
@@ -21,7 +21,7 @@ module Elastictastic
21
21
  add(
22
22
  instance.index,
23
23
  instance.id,
24
- { 'create' => bulk_identifier(instance) },
24
+ { 'create' => bulk_identifier_for_instance(instance) },
25
25
  instance.elasticsearch_doc
26
26
  ) do |response|
27
27
  if response['create']['error']
@@ -41,7 +41,7 @@ module Elastictastic
41
41
  add(
42
42
  instance.index,
43
43
  instance.id,
44
- { 'index' => bulk_identifier(instance) },
44
+ { 'index' => bulk_identifier_for_instance(instance) },
45
45
  instance.elasticsearch_doc
46
46
  ) do |response|
47
47
  if response['index']['error']
@@ -56,7 +56,7 @@ module Elastictastic
56
56
  def destroy(instance, &block)
57
57
  block ||= DEFAULT_HANDLER
58
58
  instance.pending_destroy!
59
- add(instance.index, instance.id, :delete => bulk_identifier(instance)) do |response|
59
+ add(instance.index, instance.id, :delete => bulk_identifier_for_instance(instance)) do |response|
60
60
  if response['delete']['error']
61
61
  block.call(ServerError[response['delete']['error']])
62
62
  else
@@ -67,6 +67,13 @@ module Elastictastic
67
67
  end
68
68
  end
69
69
 
70
+ def destroy!(index, type, id, routing, parent)
71
+ add(
72
+ index, id,
73
+ :delete => bulk_identifier(index, type, id, routing, parent, nil)
74
+ )
75
+ end
76
+
70
77
  def flush
71
78
  return if @operations.empty?
72
79
 
@@ -92,13 +99,23 @@ module Elastictastic
92
99
 
93
100
  private
94
101
 
95
- def bulk_identifier(instance)
96
- identifier = { :_index => instance.index.name, :_type => instance.class.type }
97
- identifier['_id'] = instance.id if instance.id
98
- identifier['_version'] = instance.version if instance.version
99
- routing = instance.class.route(instance)
102
+ def bulk_identifier_for_instance(instance)
103
+ bulk_identifier(
104
+ instance.index,
105
+ instance.class.type,
106
+ instance.id,
107
+ instance.class.route(instance),
108
+ instance._parent_id,
109
+ instance.version
110
+ )
111
+ end
112
+
113
+ def bulk_identifier(index, type, id, routing, parent_id, version)
114
+ identifier = { :_index => index.name, :_type => type }
115
+ identifier['_id'] = id if id
116
+ identifier['_version'] = version if version
100
117
  identifier['_routing'] = routing.to_s if routing
101
- identifier['parent'] = instance._parent_id if instance._parent_id
118
+ identifier['parent'] = parent_id if parent_id
102
119
  identifier
103
120
  end
104
121
 
@@ -68,8 +68,9 @@ module Elastictastic
68
68
  if url_from_env
69
69
  url_from_env.class.build(
70
70
  :host => url_from_env.host,
71
- :port => url_from_env.port
72
- )
71
+ :port => url_from_env.port,
72
+ :path => url_from_env.path
73
+ ).to_s
73
74
  else
74
75
  'http://localhost:9200'
75
76
  end
@@ -16,7 +16,7 @@ module Elastictastic
16
16
  doc.class.type,
17
17
  doc.id,
18
18
  doc.elasticsearch_doc,
19
- params_for(doc)
19
+ params_for_doc(doc)
20
20
  )
21
21
  rescue => e
22
22
  return block.call(e)
@@ -35,7 +35,7 @@ module Elastictastic
35
35
  doc.class.type,
36
36
  doc.id,
37
37
  doc.elasticsearch_doc,
38
- params_for(doc)
38
+ params_for_doc(doc)
39
39
  )
40
40
  rescue => e
41
41
  return block.call(e)
@@ -52,7 +52,7 @@ module Elastictastic
52
52
  doc.index.name,
53
53
  doc.class.type,
54
54
  doc.id,
55
- params_for(doc)
55
+ params_for_doc(doc)
56
56
  )
57
57
  rescue => e
58
58
  return block.call(e)
@@ -62,15 +62,32 @@ module Elastictastic
62
62
  response['found']
63
63
  end
64
64
 
65
+ def destroy!(index, type, id, routing, parent)
66
+ response = Elastictastic.client.delete(
67
+ index,
68
+ type,
69
+ id,
70
+ params_for(routing, parent, nil)
71
+ )
72
+ response['found']
73
+ end
74
+
65
75
  private
66
76
 
67
- def params_for(doc)
77
+ def params_for_doc(doc)
78
+ params_for(
79
+ doc.class.route(doc),
80
+ doc._parent_id,
81
+ doc.version
82
+ )
83
+ end
84
+
85
+ def params_for(routing, parent_id, version)
68
86
  {}.tap do |params|
69
87
  params[:refresh] = true if Elastictastic.config.auto_refresh
70
- params[:parent] = doc._parent_id if doc._parent_id
71
- params[:version] = doc.version if doc.version
72
- routing = doc.class.route(doc)
73
- params[:routing] = routing if routing
88
+ params[:parent] = parent_id if parent_id
89
+ params[:version] = version if version
90
+ params[:routing] = routing.to_s if routing
74
91
  end
75
92
  end
76
93
  end
@@ -3,7 +3,7 @@ module Elastictastic
3
3
  def save(options = {}, &block)
4
4
  persisted? ? update(options, &block) : create(options, &block)
5
5
  end
6
-
6
+
7
7
  def destroy(options = {}, &block)
8
8
  if persisted?
9
9
  Elastictastic.persister.destroy(self, &block)
@@ -140,6 +140,21 @@ module Elastictastic
140
140
  )
141
141
  end
142
142
 
143
+ #
144
+ # Destroy one or more documents by ID, without reading them first
145
+ #
146
+ def destroy(*ids)
147
+ ids.each do |id|
148
+ ::Elastictastic.persister.destroy!(
149
+ @index,
150
+ @clazz.type,
151
+ id,
152
+ @routing,
153
+ (@parent.id if @parent)
154
+ )
155
+ end
156
+ end
157
+
143
158
  #
144
159
  # Destroy all documents in this index.
145
160
  #
@@ -1,3 +1,3 @@
1
1
  module Elastictastic
2
- VERSION = '0.10.8'
2
+ VERSION = '0.10.9'
3
3
  end
@@ -200,6 +200,21 @@ describe Elastictastic::BulkPersistenceStrategy do
200
200
  end
201
201
  end
202
202
 
203
+ describe 'destroy!' do
204
+ before do
205
+ stub_es_bulk(
206
+ 'delete' => { '_index' => 'default', '_type' => 'post', '_id' => '123', '_version' => 2, 'ok' => true }
207
+ )
208
+ Elastictastic.bulk { Post.in_index('my_index').destroy('123') }
209
+ end
210
+
211
+ it 'should send destroy' do
212
+ bulk_requests.should == [
213
+ { 'delete' => { '_index' => 'my_index', '_type' => 'post', '_id' => '123' }}
214
+ ]
215
+ end
216
+ end
217
+
203
218
  shared_examples_for 'block with error' do
204
219
  it 'should not run bulk operation' do
205
220
  error_proc.call rescue nil
@@ -194,6 +194,45 @@ describe Elastictastic::Document do
194
194
  end
195
195
  end # describe '#save'
196
196
 
197
+ describe '::destroy' do
198
+ context 'with default index and no routing' do
199
+ before do
200
+ stub_es_destroy('default', 'post', '123')
201
+ Post.destroy('123')
202
+ end
203
+
204
+ it 'should send DELETE request' do
205
+ last_request.method.should == 'DELETE'
206
+ end
207
+
208
+ it 'should send request to document resource path' do
209
+ last_request.path.should == '/default/post/123'
210
+ end
211
+ end # context 'existing persisted object'
212
+
213
+ context 'with routing' do
214
+ before do
215
+ stub_es_destroy('default', 'photo', 'abc')
216
+ Photo.routing('123').destroy('abc')
217
+ end
218
+
219
+ it 'should include routing param' do
220
+ last_request_uri.query.split('&').should include('routing=123')
221
+ end
222
+ end
223
+
224
+ context 'on specified index' do
225
+ before do
226
+ stub_es_destroy('my_index', 'post', '123')
227
+ Post.in_index('my_index').destroy('123')
228
+ end
229
+
230
+ it 'should send request to specified index resource' do
231
+ last_request.path.should == '/my_index/post/123'
232
+ end
233
+ end
234
+ end # describe '#destroy'
235
+
197
236
  describe '#destroy' do
198
237
  context 'existing persisted object' do
199
238
  let(:post) do
@@ -81,6 +81,12 @@ describe Elastictastic::ParentChild do
81
81
  post.destroy
82
82
  URI.parse(FakeWeb.last_request.path).query.split('&').should include("parent=#{blog.id}")
83
83
  end
84
+
85
+ it 'should pass parent on ::delete' do
86
+ stub_es_destroy('default', 'post', '123')
87
+ blog.posts.destroy('123')
88
+ URI.parse(FakeWeb.last_request.path).query.split('&').should include("parent=#{blog.id}")
89
+ end
84
90
  end
85
91
 
86
92
  describe 'bulk persistence' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastictastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.8
4
+ version: 0.10.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-12-28 00:00:00.000000000 Z
14
+ date: 2013-01-09 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
18
- requirement: &8804860 !ruby/object:Gem::Requirement
18
+ requirement: !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,15 @@ dependencies:
23
23
  version: '3.0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *8804860
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ version: '3.0'
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: activemodel
29
- requirement: &8804300 !ruby/object:Gem::Requirement
34
+ requirement: !ruby/object:Gem::Requirement
30
35
  none: false
31
36
  requirements:
32
37
  - - ~>
@@ -34,10 +39,15 @@ dependencies:
34
39
  version: '3.0'
35
40
  type: :runtime
36
41
  prerelease: false
37
- version_requirements: *8804300
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
38
48
  - !ruby/object:Gem::Dependency
39
49
  name: hashie
40
- requirement: &8803880 !ruby/object:Gem::Requirement
50
+ requirement: !ruby/object:Gem::Requirement
41
51
  none: false
42
52
  requirements:
43
53
  - - ! '>='
@@ -45,10 +55,15 @@ dependencies:
45
55
  version: '0'
46
56
  type: :runtime
47
57
  prerelease: false
48
- version_requirements: *8803880
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
49
64
  - !ruby/object:Gem::Dependency
50
65
  name: i18n
51
- requirement: &8803320 !ruby/object:Gem::Requirement
66
+ requirement: !ruby/object:Gem::Requirement
52
67
  none: false
53
68
  requirements:
54
69
  - - ! '>='
@@ -56,10 +71,15 @@ dependencies:
56
71
  version: '0'
57
72
  type: :runtime
58
73
  prerelease: false
59
- version_requirements: *8803320
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
60
80
  - !ruby/object:Gem::Dependency
61
81
  name: multi_json
62
- requirement: &8802880 !ruby/object:Gem::Requirement
82
+ requirement: !ruby/object:Gem::Requirement
63
83
  none: false
64
84
  requirements:
65
85
  - - ! '>='
@@ -67,10 +87,15 @@ dependencies:
67
87
  version: '0'
68
88
  type: :runtime
69
89
  prerelease: false
70
- version_requirements: *8802880
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
71
96
  - !ruby/object:Gem::Dependency
72
97
  name: rspec
73
- requirement: &8802260 !ruby/object:Gem::Requirement
98
+ requirement: !ruby/object:Gem::Requirement
74
99
  none: false
75
100
  requirements:
76
101
  - - ~>
@@ -78,10 +103,15 @@ dependencies:
78
103
  version: '2.0'
79
104
  type: :development
80
105
  prerelease: false
81
- version_requirements: *8802260
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: '2.0'
82
112
  - !ruby/object:Gem::Dependency
83
113
  name: fakeweb
84
- requirement: &8801580 !ruby/object:Gem::Requirement
114
+ requirement: !ruby/object:Gem::Requirement
85
115
  none: false
86
116
  requirements:
87
117
  - - ~>
@@ -89,10 +119,15 @@ dependencies:
89
119
  version: '1.3'
90
120
  type: :development
91
121
  prerelease: false
92
- version_requirements: *8801580
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ~>
126
+ - !ruby/object:Gem::Version
127
+ version: '1.3'
93
128
  - !ruby/object:Gem::Dependency
94
129
  name: yard
95
- requirement: &8800940 !ruby/object:Gem::Requirement
130
+ requirement: !ruby/object:Gem::Requirement
96
131
  none: false
97
132
  requirements:
98
133
  - - ~>
@@ -100,7 +135,12 @@ dependencies:
100
135
  version: '0.6'
101
136
  type: :development
102
137
  prerelease: false
103
- version_requirements: *8800940
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ~>
142
+ - !ruby/object:Gem::Version
143
+ version: '0.6'
104
144
  description: ! 'Elastictastic is an object-document mapper and lightweight API adapter
105
145
  for
106
146
 
@@ -117,74 +157,74 @@ extensions: []
117
157
  extra_rdoc_files:
118
158
  - README.md
119
159
  files:
120
- - lib/elastictastic/multi_search.rb
121
- - lib/elastictastic/transport_methods.rb
122
- - lib/elastictastic/basic_document.rb
123
- - lib/elastictastic/observer.rb
124
- - lib/elastictastic/middleware.rb
125
- - lib/elastictastic/child_collection_proxy.rb
126
- - lib/elastictastic/dirty.rb
127
- - lib/elastictastic/rotor.rb
128
- - lib/elastictastic/errors.rb
129
- - lib/elastictastic/scope.rb
130
- - lib/elastictastic/discrete_persistence_strategy.rb
131
- - lib/elastictastic/parent_child.rb
132
- - lib/elastictastic/adapter.rb
133
- - lib/elastictastic/embedded_document.rb
134
- - lib/elastictastic/new_relic_instrumentation.rb
160
+ - lib/elastictastic.rb
135
161
  - lib/elastictastic/optimistic_locking.rb
136
- - lib/elastictastic/callbacks.rb
137
- - lib/elastictastic/util.rb
138
- - lib/elastictastic/nested_document.rb
139
- - lib/elastictastic/association.rb
140
- - lib/elastictastic/client.rb
162
+ - lib/elastictastic/server_error.rb
141
163
  - lib/elastictastic/document.rb
142
- - lib/elastictastic/properties.rb
143
- - lib/elastictastic/test_helpers.rb
144
- - lib/elastictastic/search.rb
145
- - lib/elastictastic/thrift/types.rb
146
- - lib/elastictastic/thrift/rest.rb
147
- - lib/elastictastic/thrift/constants.rb
148
- - lib/elastictastic/multi_get.rb
164
+ - lib/elastictastic/nested_document.rb
165
+ - lib/elastictastic/child_collection_proxy.rb
149
166
  - lib/elastictastic/mass_assignment_security.rb
150
- - lib/elastictastic/server_error.rb
151
- - lib/elastictastic/version.rb
152
167
  - lib/elastictastic/scope_builder.rb
153
- - lib/elastictastic/persistence.rb
154
- - lib/elastictastic/observing.rb
168
+ - lib/elastictastic/util.rb
155
169
  - lib/elastictastic/index.rb
156
- - lib/elastictastic/validations.rb
157
170
  - lib/elastictastic/bulk_persistence_strategy.rb
158
- - lib/elastictastic/field.rb
159
- - lib/elastictastic/scoped.rb
171
+ - lib/elastictastic/basic_document.rb
172
+ - lib/elastictastic/thrift/rest.rb
173
+ - lib/elastictastic/thrift/constants.rb
174
+ - lib/elastictastic/thrift/types.rb
175
+ - lib/elastictastic/multi_search.rb
176
+ - lib/elastictastic/association.rb
177
+ - lib/elastictastic/adapter.rb
178
+ - lib/elastictastic/discrete_persistence_strategy.rb
179
+ - lib/elastictastic/callbacks.rb
180
+ - lib/elastictastic/observer.rb
181
+ - lib/elastictastic/embedded_document.rb
182
+ - lib/elastictastic/test_helpers.rb
160
183
  - lib/elastictastic/thrift_adapter.rb
184
+ - lib/elastictastic/version.rb
185
+ - lib/elastictastic/validations.rb
186
+ - lib/elastictastic/persistence.rb
161
187
  - lib/elastictastic/railtie.rb
188
+ - lib/elastictastic/client.rb
189
+ - lib/elastictastic/properties.rb
190
+ - lib/elastictastic/rotor.rb
191
+ - lib/elastictastic/multi_get.rb
192
+ - lib/elastictastic/parent_child.rb
193
+ - lib/elastictastic/field.rb
194
+ - lib/elastictastic/scope.rb
195
+ - lib/elastictastic/scoped.rb
196
+ - lib/elastictastic/new_relic_instrumentation.rb
197
+ - lib/elastictastic/search.rb
198
+ - lib/elastictastic/transport_methods.rb
199
+ - lib/elastictastic/middleware.rb
162
200
  - lib/elastictastic/configuration.rb
163
- - lib/elastictastic.rb
164
- - spec/models/photo.rb
165
- - spec/models/post.rb
166
- - spec/models/blog.rb
167
- - spec/models/author.rb
168
- - spec/models/post_observer.rb
169
- - spec/models/comment.rb
201
+ - lib/elastictastic/dirty.rb
202
+ - lib/elastictastic/errors.rb
203
+ - lib/elastictastic/observing.rb
170
204
  - spec/environment.rb
171
- - spec/examples/callbacks_spec.rb
172
- - spec/examples/mass_assignment_security_spec.rb
173
- - spec/examples/rotor_spec.rb
174
- - spec/examples/middleware_spec.rb
175
- - spec/examples/optimistic_locking_spec.rb
176
- - spec/examples/parent_child_spec.rb
177
- - spec/examples/scope_spec.rb
178
205
  - spec/examples/bulk_persistence_strategy_spec.rb
206
+ - spec/examples/document_spec.rb
179
207
  - spec/examples/properties_spec.rb
208
+ - spec/examples/validation_spec.rb
209
+ - spec/examples/optimistic_locking_spec.rb
210
+ - spec/examples/middleware_spec.rb
211
+ - spec/examples/mass_assignment_security_spec.rb
212
+ - spec/examples/dirty_spec.rb
213
+ - spec/examples/spec_helper.rb
180
214
  - spec/examples/multi_search_spec.rb
215
+ - spec/examples/rotor_spec.rb
216
+ - spec/examples/callbacks_spec.rb
181
217
  - spec/examples/multi_get_spec.rb
182
- - spec/examples/search_spec.rb
183
- - spec/examples/document_spec.rb
184
- - spec/examples/dirty_spec.rb
185
- - spec/examples/validation_spec.rb
218
+ - spec/examples/scope_spec.rb
219
+ - spec/examples/parent_child_spec.rb
186
220
  - spec/examples/observing_spec.rb
187
- - spec/examples/spec_helper.rb
221
+ - spec/examples/search_spec.rb
222
+ - spec/models/post_observer.rb
223
+ - spec/models/author.rb
224
+ - spec/models/blog.rb
225
+ - spec/models/post.rb
226
+ - spec/models/photo.rb
227
+ - spec/models/comment.rb
188
228
  - spec/support/fakeweb_request_history.rb
189
229
  - README.md
190
230
  - LICENSE
@@ -210,26 +250,26 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
250
  requirements:
211
251
  - ElasticSearch
212
252
  rubyforge_project:
213
- rubygems_version: 1.8.15
253
+ rubygems_version: 1.8.24
214
254
  signing_key:
215
255
  specification_version: 3
216
256
  summary: Object-document mapper for ElasticSearch
217
257
  test_files:
218
- - spec/examples/callbacks_spec.rb
219
- - spec/examples/mass_assignment_security_spec.rb
220
- - spec/examples/rotor_spec.rb
221
- - spec/examples/middleware_spec.rb
222
- - spec/examples/optimistic_locking_spec.rb
223
- - spec/examples/parent_child_spec.rb
224
- - spec/examples/scope_spec.rb
225
258
  - spec/examples/bulk_persistence_strategy_spec.rb
259
+ - spec/examples/document_spec.rb
226
260
  - spec/examples/properties_spec.rb
261
+ - spec/examples/validation_spec.rb
262
+ - spec/examples/optimistic_locking_spec.rb
263
+ - spec/examples/middleware_spec.rb
264
+ - spec/examples/mass_assignment_security_spec.rb
265
+ - spec/examples/dirty_spec.rb
266
+ - spec/examples/spec_helper.rb
227
267
  - spec/examples/multi_search_spec.rb
268
+ - spec/examples/rotor_spec.rb
269
+ - spec/examples/callbacks_spec.rb
228
270
  - spec/examples/multi_get_spec.rb
229
- - spec/examples/search_spec.rb
230
- - spec/examples/document_spec.rb
231
- - spec/examples/dirty_spec.rb
232
- - spec/examples/validation_spec.rb
271
+ - spec/examples/scope_spec.rb
272
+ - spec/examples/parent_child_spec.rb
233
273
  - spec/examples/observing_spec.rb
234
- - spec/examples/spec_helper.rb
274
+ - spec/examples/search_spec.rb
235
275
  has_rdoc: true