elasticsearch-model 7.0.0 → 7.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/README.md +15 -27
- data/Rakefile +13 -14
- data/elasticsearch-model.gemspec +37 -40
- data/examples/activerecord_article.rb +1 -1
- data/examples/activerecord_associations.rb +2 -2
- data/examples/activerecord_custom_analyzer.rb +3 -3
- data/examples/activerecord_mapping_completion.rb +1 -1
- data/examples/activerecord_mapping_edge_ngram.rb +1 -1
- data/examples/couchbase_article.rb +1 -1
- data/examples/datamapper_article.rb +1 -1
- data/examples/mongoid_article.rb +1 -1
- data/examples/ohm_article.rb +1 -1
- data/examples/riak_article.rb +1 -1
- data/gemfiles/4.0.gemfile +4 -3
- data/lib/elasticsearch/model/adapter.rb +1 -1
- data/lib/elasticsearch/model/adapters/active_record.rb +2 -2
- data/lib/elasticsearch/model/adapters/default.rb +1 -1
- data/lib/elasticsearch/model/adapters/mongoid.rb +1 -1
- data/lib/elasticsearch/model/adapters/multiple.rb +1 -1
- data/lib/elasticsearch/model/callbacks.rb +1 -1
- data/lib/elasticsearch/model/client.rb +1 -6
- data/lib/elasticsearch/model/ext/active_record.rb +1 -1
- data/lib/elasticsearch/model/hash_wrapper.rb +1 -1
- data/lib/elasticsearch/model/importing.rb +11 -5
- data/lib/elasticsearch/model/indexing.rb +4 -4
- data/lib/elasticsearch/model/multimodel.rb +2 -2
- data/lib/elasticsearch/model/naming.rb +1 -1
- data/lib/elasticsearch/model/proxy.rb +7 -4
- data/lib/elasticsearch/model/response/aggregations.rb +1 -1
- data/lib/elasticsearch/model/response/base.rb +1 -1
- data/lib/elasticsearch/model/response/pagination/kaminari.rb +1 -1
- data/lib/elasticsearch/model/response/pagination/will_paginate.rb +1 -1
- data/lib/elasticsearch/model/response/pagination.rb +1 -1
- data/lib/elasticsearch/model/response/records.rb +1 -1
- data/lib/elasticsearch/model/response/result.rb +1 -1
- data/lib/elasticsearch/model/response/results.rb +2 -1
- data/lib/elasticsearch/model/response/suggestions.rb +1 -1
- data/lib/elasticsearch/model/response.rb +1 -1
- data/lib/elasticsearch/model/searching.rb +1 -1
- data/lib/elasticsearch/model/serializing.rb +1 -1
- data/lib/elasticsearch/model/version.rb +2 -2
- data/lib/elasticsearch/model.rb +4 -4
- data/spec/elasticsearch/model/adapter_spec.rb +1 -1
- data/spec/elasticsearch/model/adapters/active_record/associations_spec.rb +1 -1
- data/spec/elasticsearch/model/adapters/active_record/basic_spec.rb +1 -1
- data/spec/elasticsearch/model/adapters/active_record/dynamic_index_name_spec.rb +1 -1
- data/spec/elasticsearch/model/adapters/active_record/import_spec.rb +2 -13
- data/spec/elasticsearch/model/adapters/active_record/multi_model_spec.rb +1 -1
- data/spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb +1 -1
- data/spec/elasticsearch/model/adapters/active_record/pagination_spec.rb +1 -1
- data/spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb +1 -1
- data/spec/elasticsearch/model/adapters/active_record/serialization_spec.rb +1 -1
- data/spec/elasticsearch/model/adapters/active_record_spec.rb +1 -1
- data/spec/elasticsearch/model/adapters/default_spec.rb +1 -1
- data/spec/elasticsearch/model/adapters/mongoid/basic_spec.rb +1 -1
- data/spec/elasticsearch/model/adapters/mongoid/multi_model_spec.rb +12 -12
- data/spec/elasticsearch/model/adapters/mongoid_spec.rb +1 -1
- data/spec/elasticsearch/model/adapters/multiple_spec.rb +1 -1
- data/spec/elasticsearch/model/callbacks_spec.rb +1 -1
- data/spec/elasticsearch/model/client_spec.rb +4 -4
- data/spec/elasticsearch/model/hash_wrapper_spec.rb +1 -1
- data/spec/elasticsearch/model/importing_spec.rb +13 -1
- data/spec/elasticsearch/model/indexing_spec.rb +17 -42
- data/spec/elasticsearch/model/module_spec.rb +3 -2
- data/spec/elasticsearch/model/multimodel_spec.rb +1 -1
- data/spec/elasticsearch/model/naming_spec.rb +1 -1
- data/spec/elasticsearch/model/proxy_spec.rb +10 -2
- data/spec/elasticsearch/model/response/aggregations_spec.rb +1 -1
- data/spec/elasticsearch/model/response/base_spec.rb +1 -1
- data/spec/elasticsearch/model/response/pagination/kaminari_spec.rb +1 -1
- data/spec/elasticsearch/model/response/pagination/will_paginate_spec.rb +1 -1
- data/spec/elasticsearch/model/response/records_spec.rb +1 -1
- data/spec/elasticsearch/model/response/response_spec.rb +1 -1
- data/spec/elasticsearch/model/response/result_spec.rb +1 -1
- data/spec/elasticsearch/model/response/results_spec.rb +13 -1
- data/spec/elasticsearch/model/searching_search_request_spec.rb +1 -1
- data/spec/elasticsearch/model/searching_spec.rb +1 -1
- data/spec/elasticsearch/model/serializing_spec.rb +1 -1
- data/spec/spec_helper.rb +11 -3
- data/spec/support/app/answer.rb +2 -2
- data/spec/support/app/article.rb +1 -1
- data/spec/support/app/article_for_pagination.rb +1 -1
- data/spec/support/app/article_no_type.rb +1 -1
- data/spec/support/app/article_with_custom_serialization.rb +1 -1
- data/spec/support/app/article_with_dynamic_index_name.rb +1 -1
- data/spec/support/app/author.rb +1 -1
- data/spec/support/app/authorship.rb +1 -1
- data/spec/support/app/category.rb +1 -1
- data/spec/support/app/comment.rb +1 -1
- data/spec/support/app/episode.rb +1 -1
- data/spec/support/app/image.rb +1 -1
- data/spec/support/app/import_article.rb +1 -1
- data/spec/support/app/mongoid_article.rb +1 -1
- data/spec/support/app/namespaced_book.rb +1 -1
- data/spec/support/app/parent_and_child_searchable.rb +1 -1
- data/spec/support/app/post.rb +1 -1
- data/spec/support/app/question.rb +1 -1
- data/spec/support/app/searchable.rb +1 -1
- data/spec/support/app/series.rb +1 -1
- data/spec/support/app.rb +2 -2
- metadata +40 -54
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -270,7 +270,7 @@ module Elasticsearch
|
|
270
270
|
def index_exists?(options={})
|
271
271
|
target_index = options[:index] || self.index_name
|
272
272
|
|
273
|
-
self.client.indices.exists(index: target_index
|
273
|
+
self.client.indices.exists(index: target_index, ignore: 404)
|
274
274
|
end
|
275
275
|
|
276
276
|
# Deletes the index with corresponding name
|
@@ -290,7 +290,7 @@ module Elasticsearch
|
|
290
290
|
self.client.indices.delete index: target_index
|
291
291
|
rescue Exception => e
|
292
292
|
if e.class.to_s =~ /NotFound/ && options[:force]
|
293
|
-
client.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.logger
|
293
|
+
client.transport.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.transport.logger
|
294
294
|
nil
|
295
295
|
else
|
296
296
|
raise e
|
@@ -317,7 +317,7 @@ module Elasticsearch
|
|
317
317
|
self.client.indices.refresh index: target_index
|
318
318
|
rescue Exception => e
|
319
319
|
if e.class.to_s =~ /NotFound/ && options[:force]
|
320
|
-
client.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.logger
|
320
|
+
client.transport.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.transport.logger
|
321
321
|
nil
|
322
322
|
else
|
323
323
|
raise e
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -85,7 +85,7 @@ module Elasticsearch
|
|
85
85
|
# @return [Array] the list of document types used for retrieving documents
|
86
86
|
#
|
87
87
|
def document_type
|
88
|
-
models.map { |m| m.document_type }
|
88
|
+
models.map { |m| m.document_type }.compact.presence
|
89
89
|
end
|
90
90
|
|
91
91
|
# Get the client common for all models
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -115,15 +115,18 @@ module Elasticsearch
|
|
115
115
|
@target = target
|
116
116
|
end
|
117
117
|
|
118
|
-
|
118
|
+
def ruby2_keywords(*) # :nodoc:
|
119
|
+
end if RUBY_VERSION < "2.7"
|
120
|
+
|
121
|
+
# Delegate methods to `@target`. As per [the Ruby 3.0 explanation for keyword arguments](https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/), the only way to work on Ruby <2.7, and 2.7, and 3.0+ is to use `ruby2_keywords`.
|
119
122
|
#
|
120
|
-
def method_missing(method_name, *arguments, &block)
|
123
|
+
ruby2_keywords def method_missing(method_name, *arguments, &block)
|
121
124
|
target.respond_to?(method_name) ? target.__send__(method_name, *arguments, &block) : super
|
122
125
|
end
|
123
126
|
|
124
127
|
# Respond to methods from `@target`
|
125
128
|
#
|
126
|
-
def
|
129
|
+
def respond_to_missing?(method_name, include_private = false)
|
127
130
|
target.respond_to?(method_name) || super
|
128
131
|
end
|
129
132
|
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -42,6 +42,7 @@ module Elasticsearch
|
|
42
42
|
response.response['hits']['hits'].map { |hit| Result.new(hit) }
|
43
43
|
end
|
44
44
|
|
45
|
+
alias records results
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -17,6 +17,6 @@
|
|
17
17
|
|
18
18
|
module Elasticsearch
|
19
19
|
module Model
|
20
|
-
VERSION = "7.
|
20
|
+
VERSION = "7.2.1"
|
21
21
|
end
|
22
22
|
end
|
data/lib/elasticsearch/model.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -112,7 +112,7 @@ module Elasticsearch
|
|
112
112
|
# Delegate common methods to the `__elasticsearch__` ClassMethodsProxy, unless they are defined already
|
113
113
|
class << self
|
114
114
|
METHODS.each do |method|
|
115
|
-
delegate method, to: :__elasticsearch__ unless self.
|
115
|
+
delegate method, to: :__elasticsearch__ unless self.public_instance_methods.include?(method)
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
@@ -127,7 +127,7 @@ module Elasticsearch
|
|
127
127
|
# @example Get the client
|
128
128
|
#
|
129
129
|
# Elasticsearch::Model.client
|
130
|
-
# => #<Elasticsearch::
|
130
|
+
# => #<Elasticsearch::Client:0x007f96a7d0d000... >
|
131
131
|
#
|
132
132
|
def client
|
133
133
|
@client ||= Elasticsearch::Client.new
|
@@ -138,7 +138,7 @@ module Elasticsearch
|
|
138
138
|
# @example Configure (set) the client for all models
|
139
139
|
#
|
140
140
|
# Elasticsearch::Model.client = Elasticsearch::Client.new host: 'http://localhost:9200', tracer: true
|
141
|
-
# => #<Elasticsearch::
|
141
|
+
# => #<Elasticsearch::Client:0x007f96a6dd0d80... >
|
142
142
|
#
|
143
143
|
# @note You have to set the client before you call Elasticsearch methods on the model,
|
144
144
|
# or set it directly on the model; see {Elasticsearch::Model::Client::ClassMethods#client}
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -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:
|
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
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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:
|
40
|
-
Episode.create name:
|
41
|
-
Episode.create name:
|
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:
|
46
|
-
Image.create! name:
|
47
|
-
Image.create! name:
|
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
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -33,14 +33,14 @@ describe Elasticsearch::Model::Client do
|
|
33
33
|
context 'when a class includes the client module class methods' do
|
34
34
|
|
35
35
|
it 'defines the client module class methods on the model' do
|
36
|
-
expect(DummyClientModel.client).to be_a(Elasticsearch::
|
36
|
+
expect(DummyClientModel.client).to be_a(Elasticsearch::Client)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
context 'when a class includes the client module instance methods' do
|
41
41
|
|
42
42
|
it 'defines the client module class methods on the model' do
|
43
|
-
expect(DummyClientModel.new.client).to be_a(Elasticsearch::
|
43
|
+
expect(DummyClientModel.new.client).to be_a(Elasticsearch::Client)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -77,7 +77,7 @@ describe Elasticsearch::Model::Client do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'does not set the client on the class' do
|
80
|
-
expect(DummyClientModel.client).to be_a(Elasticsearch::
|
80
|
+
expect(DummyClientModel.client).to be_a(Elasticsearch::Client)
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
10
|
#
|
11
11
|
# Unless required by applicable law or agreed to in writing,
|
12
12
|
# software distributed under the License is distributed on an
|
@@ -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
|