elasticsearch-model 7.0.0 → 7.1.0.pre

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
  SHA256:
3
- metadata.gz: 1ced6c99b3278104e708dc2db19a73422273f92b9c18d3aa1f0d552e0ba27d97
4
- data.tar.gz: 9075efe50a3f7da082933e3e9acc9751901dc4561f92a70c4d3cbea000c581ee
3
+ metadata.gz: b92bc72627459220a08885cccd70605e9123b44f23561438fa71d11bf6e64ff5
4
+ data.tar.gz: 0bf5e719b65b1dda889680f7058676207522293acee1285a6d4d8af6877556fa
5
5
  SHA512:
6
- metadata.gz: b8f7d0e726d805048544b8ffce8a81b269be4f17c3696241372f6258a7c9add622998718fb23c35b752cc1a51d64a0b8ef42a293b31718f6ba4ed51cfced7586
7
- data.tar.gz: 36e3325b72bfa63f8ea133b44086d579bb8727a6e5d8c71115ab25d424b6058e849a32aa68326f5450c1f0fbe5c75fedead8878893309ffbca29901c773367be
6
+ metadata.gz: 2088cc1213eb7f0f6a078029c386f3f41ecdcf60ba88c0e5d8a6aaccea3564cc4a0c34128fd14b0ac6631d34b8d3ecea46ec901fcad6874b052f3766f6ce6850
7
+ data.tar.gz: 0721dac95902a27db984c68a49b91cd6b9ad8ceda1c5da3ade39acf5a083ea20423757d4d2391d34103532a1768e673f53f89d086d8c4c1e7437e9c66ef75612
data/README.md CHANGED
@@ -533,7 +533,7 @@ class Indexer
533
533
  Logger = Sidekiq.logger.level == Logger::DEBUG ? Sidekiq.logger : nil
534
534
  Client = Elasticsearch::Client.new host: 'localhost:9200', logger: Logger
535
535
 
536
- def perform_async(operation, record_id)
536
+ def perform(operation, record_id)
537
537
  logger.debug [operation, "ID: #{record_id}"]
538
538
 
539
539
  case operation.to_s
data/Rakefile CHANGED
@@ -15,17 +15,13 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- require "bundler/gem_tasks"
18
+ require 'bundler/gem_tasks'
19
19
 
20
- desc "Run unit tests"
21
- task :default => 'test:unit'
22
- task :test => 'test:unit'
20
+ desc 'Run unit tests'
21
+ task default: 'test:all'
22
+ task test: 'test:all'
23
23
 
24
- if RUBY_VERSION < '2.3'
25
- GEMFILES = ['3.0.gemfile', '4.0.gemfile', '5.0.gemfile']
26
- else
27
- GEMFILES = ['4.0.gemfile', '5.0.gemfile', '6.0.gemfile']
28
- end
24
+ GEMFILES = ['4.0.gemfile', '5.0.gemfile', '6.0.gemfile']
29
25
 
30
26
  namespace :bundle do
31
27
  desc 'Install dependencies for all the Gemfiles in /gemfiles. Optionally define env variable RAILS_VERSIONS. E.g. RAILS_VERSIONS=3.0,5.0'
@@ -47,7 +43,6 @@ end
47
43
 
48
44
  require 'rake/testtask'
49
45
  namespace :test do
50
-
51
46
  desc 'Run all tests. Optionally define env variable RAILS_VERSIONS. E.g. RAILS_VERSIONS=3.0,5.0'
52
47
  task :all, [:rails_versions] do |task, args|
53
48
  gemfiles = ENV['RAILS_VERSIONS'] ? ENV['RAILS_VERSIONS'].split(',').map {|v| "#{v}.gemfile"} : GEMFILES
@@ -45,7 +45,7 @@ Gem::Specification.new do |s|
45
45
  s.add_dependency "hashie"
46
46
 
47
47
  s.add_development_dependency "bundler"
48
- s.add_development_dependency "rake", "~> 11.1"
48
+ s.add_development_dependency "rake", "~> 12"
49
49
 
50
50
  s.add_development_dependency "elasticsearch-extensions"
51
51
 
@@ -143,6 +143,7 @@ module Elasticsearch
143
143
  target_index = options.delete(:index) || index_name
144
144
  target_type = options.delete(:type) || document_type
145
145
  transform = options.delete(:transform) || __transform
146
+ pipeline = options.delete(:pipeline)
146
147
  return_value = options.delete(:return) || 'count'
147
148
 
148
149
  unless transform.respond_to?(:call)
@@ -158,10 +159,15 @@ module Elasticsearch
158
159
  end
159
160
 
160
161
  __find_in_batches(options) do |batch|
161
- response = client.bulk \
162
- index: target_index,
163
- type: target_type,
164
- body: __batch_to_bulk(batch, transform)
162
+ params = {
163
+ index: target_index,
164
+ type: target_type,
165
+ body: __batch_to_bulk(batch, transform)
166
+ }
167
+
168
+ params[:pipeline] = pipeline if pipeline
169
+
170
+ response = client.bulk params
165
171
 
166
172
  yield response if block_given?
167
173
 
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Elasticsearch
19
19
  module Model
20
- VERSION = "7.0.0"
20
+ VERSION = "7.1.0.pre"
21
21
  end
22
22
  end
@@ -18,7 +18,6 @@
18
18
  require 'spec_helper'
19
19
 
20
20
  describe 'Elasticsearch::Model::Adapter::ActiveRecord Importing' do
21
-
22
21
  before(:all) do
23
22
  ActiveRecord::Schema.define(:version => 1) do
24
23
  create_table :import_articles do |t|
@@ -43,11 +42,9 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Importing' do
43
42
  end
44
43
 
45
44
  describe '#import' do
46
-
47
45
  context 'when no search criteria is specified' do
48
-
49
46
  before do
50
- 10.times { |i| ImportArticle.create! title: 'Test', views: "#{i}" }
47
+ 10.times { |i| ImportArticle.create! title: 'Test', views: i.to_s }
51
48
  ImportArticle.import
52
49
  ImportArticle.__elasticsearch__.refresh_index!
53
50
  end
@@ -58,7 +55,6 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Importing' do
58
55
  end
59
56
 
60
57
  context 'when batch size is specified' do
61
-
62
58
  before do
63
59
  10.times { |i| ImportArticle.create! title: 'Test', views: "#{i}" }
64
60
  end
@@ -82,7 +78,6 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Importing' do
82
78
  end
83
79
 
84
80
  context 'when a scope is specified' do
85
-
86
81
  before do
87
82
  10.times { |i| ImportArticle.create! title: 'Test', views: "#{i}" }
88
83
  ImportArticle.import(scope: 'popular', force: true)
@@ -95,7 +90,6 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Importing' do
95
90
  end
96
91
 
97
92
  context 'when a query is specified' do
98
-
99
93
  before do
100
94
  10.times { |i| ImportArticle.create! title: 'Test', views: "#{i}" }
101
95
  ImportArticle.import(query: -> { where('views >= 3') })
@@ -108,7 +102,6 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Importing' do
108
102
  end
109
103
 
110
104
  context 'when there are invalid documents' do
111
-
112
105
  let!(:result) do
113
106
  10.times { |i| ImportArticle.create! title: 'Test', views: "#{i}" }
114
107
  new_article
@@ -132,7 +125,6 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Importing' do
132
125
  end
133
126
 
134
127
  context 'when a transform proc is specified' do
135
-
136
128
  before do
137
129
  10.times { |i| ImportArticle.create! title: 'Test', views: "#{i}" }
138
130
  ImportArticle.import( transform: ->(a) {{ index: { data: { name: a.title, foo: 'BAR' } }}} )
@@ -151,7 +143,6 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Importing' do
151
143
  end
152
144
 
153
145
  context 'when the model has a default scope' do
154
-
155
146
  around(:all) do |example|
156
147
  10.times { |i| ImportArticle.create! title: 'Test', views: "#{i}" }
157
148
  ImportArticle.instance_eval { default_scope { where('views > 3') } }
@@ -170,7 +161,6 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Importing' do
170
161
  end
171
162
 
172
163
  context 'when there is a default scope and a query specified' do
173
-
174
164
  around(:all) do |example|
175
165
  10.times { |i| ImportArticle.create! title: 'Test', views: "#{i}" }
176
166
  ImportArticle.instance_eval { default_scope { where('views > 3') } }
@@ -189,7 +179,6 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Importing' do
189
179
  end
190
180
 
191
181
  context 'when the batch is empty' do
192
-
193
182
  before do
194
183
  ImportArticle.delete_all
195
184
  ImportArticle.import
@@ -24,10 +24,10 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Multimodel', if: test_mong
24
24
 
25
25
  begin
26
26
  ActiveRecord::Schema.define(:version => 1) do
27
- create_table Episode.table_name do |t|
28
- t.string :name
29
- t.datetime :created_at, :default => 'NOW()'
30
- end
27
+ create_table Episode.table_name do |t|
28
+ t.string :name
29
+ t.datetime :created_at, :default => 'NOW()'
30
+ end
31
31
  end
32
32
  rescue
33
33
  end
@@ -36,22 +36,22 @@ describe 'Elasticsearch::Model::Adapter::ActiveRecord Multimodel', if: test_mong
36
36
  before do
37
37
  clear_tables(Episode, Image)
38
38
  Episode.__elasticsearch__.create_index! force: true
39
- Episode.create name: "TheEpisode"
40
- Episode.create name: "A great Episode"
41
- Episode.create name: "The greatest Episode"
39
+ Episode.create name: 'TheEpisode'
40
+ Episode.create name: 'A great Episode'
41
+ Episode.create name: 'The greatest Episode'
42
42
  Episode.__elasticsearch__.refresh_index!
43
43
 
44
44
  Image.__elasticsearch__.create_index! force: true
45
- Image.create! name: "The Image"
46
- Image.create! name: "A great Image"
47
- Image.create! name: "The greatest Image"
45
+ Image.create! name: 'The Image'
46
+ Image.create! name: 'A great Image'
47
+ Image.create! name: 'The greatest Image'
48
48
  Image.__elasticsearch__.refresh_index!
49
49
  Image.__elasticsearch__.client.cluster.health wait_for_status: 'yellow'
50
50
  end
51
51
 
52
52
  after do
53
53
  [Episode, Image].each do |model|
54
- model.__elasticsearch__.client.delete_by_query(index: model.index_name, q: '*')
54
+ model.__elasticsearch__.client.delete_by_query(index: model.index_name, q: '*', body: {})
55
55
  model.delete_all
56
56
  model.__elasticsearch__.refresh_index!
57
57
  end
@@ -227,5 +227,17 @@ describe Elasticsearch::Model::Importing do
227
227
  end
228
228
  end
229
229
  end
230
+
231
+ context 'when a pipeline is provided as an options' do
232
+
233
+ before do
234
+ expect(DummyImportingModel).to receive(:client).and_return(client)
235
+ expect(client).to receive(:bulk).with(body: nil, index: 'foo', type: 'foo', pipeline: 'my-pipeline').and_return(response)
236
+ end
237
+
238
+ it 'uses the pipeline option' do
239
+ expect(DummyImportingModel.import(pipeline: 'my-pipeline')).to eq(0)
240
+ end
241
+ end
230
242
  end
231
243
  end
@@ -81,8 +81,16 @@ end
81
81
  # @since 6.0.1
82
82
  def clear_indices(*models)
83
83
  models.each do |model|
84
- begin; Elasticsearch::Model.client.delete_by_query(index: model.index_name, q: '*'); rescue; end
85
- end and true
84
+ begin
85
+ Elasticsearch::Model.client.delete_by_query(
86
+ index: model.index_name,
87
+ q: '*',
88
+ body: {}
89
+ )
90
+ rescue
91
+ end
92
+ end
93
+ true
86
94
  end
87
95
 
88
96
  # Delete all documents from the tables of the provided list of models.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 7.1.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karel Minarik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-21 00:00:00.000000000 Z
11
+ date: 2020-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: elasticsearch
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '11.1'
75
+ version: '12'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '11.1'
82
+ version: '12'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: elasticsearch-extensions
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -452,11 +452,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
452
452
  version: 1.9.3
453
453
  required_rubygems_version: !ruby/object:Gem::Requirement
454
454
  requirements:
455
- - - ">="
455
+ - - ">"
456
456
  - !ruby/object:Gem::Version
457
- version: '0'
457
+ version: 1.3.1
458
458
  requirements: []
459
- rubygems_version: 3.0.6
459
+ rubygems_version: 3.1.2
460
460
  signing_key:
461
461
  specification_version: 4
462
462
  summary: ActiveModel/Record integrations for Elasticsearch.