elasticsearch-model 6.1.0 → 7.0.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 +4 -4
- data/.gitignore +3 -3
- data/Gemfile +17 -0
- data/LICENSE.txt +199 -10
- data/README.md +36 -25
- data/Rakefile +18 -1
- data/elasticsearch-model.gemspec +17 -0
- data/examples/activerecord_article.rb +17 -0
- data/examples/activerecord_associations.rb +33 -0
- data/examples/activerecord_custom_analyzer.rb +17 -0
- data/examples/activerecord_mapping_completion.rb +17 -0
- data/examples/activerecord_mapping_edge_ngram.rb +17 -0
- data/examples/couchbase_article.rb +17 -0
- data/examples/datamapper_article.rb +17 -0
- data/examples/mongoid_article.rb +17 -0
- data/examples/ohm_article.rb +17 -0
- data/examples/riak_article.rb +17 -0
- data/gemfiles/3.0.gemfile +18 -1
- data/gemfiles/4.0.gemfile +18 -1
- data/gemfiles/5.0.gemfile +17 -0
- data/gemfiles/6.0.gemfile +36 -0
- data/lib/elasticsearch/model/adapter.rb +17 -0
- data/lib/elasticsearch/model/adapters/active_record.rb +17 -0
- data/lib/elasticsearch/model/adapters/default.rb +17 -0
- data/lib/elasticsearch/model/adapters/mongoid.rb +17 -0
- data/lib/elasticsearch/model/adapters/multiple.rb +29 -4
- data/lib/elasticsearch/model/callbacks.rb +17 -0
- data/lib/elasticsearch/model/client.rb +17 -0
- data/lib/elasticsearch/model/ext/active_record.rb +17 -0
- data/lib/elasticsearch/model/hash_wrapper.rb +17 -0
- data/lib/elasticsearch/model/importing.rb +50 -12
- data/lib/elasticsearch/model/indexing.rb +69 -43
- data/lib/elasticsearch/model/multimodel.rb +17 -0
- data/lib/elasticsearch/model/naming.rb +19 -19
- data/lib/elasticsearch/model/proxy.rb +58 -21
- data/lib/elasticsearch/model/response/aggregations.rb +17 -0
- data/lib/elasticsearch/model/response/base.rb +22 -1
- data/lib/elasticsearch/model/response/pagination/kaminari.rb +17 -0
- data/lib/elasticsearch/model/response/pagination/will_paginate.rb +17 -0
- data/lib/elasticsearch/model/response/pagination.rb +17 -0
- data/lib/elasticsearch/model/response/records.rb +17 -1
- data/lib/elasticsearch/model/response/result.rb +17 -0
- data/lib/elasticsearch/model/response/results.rb +17 -0
- data/lib/elasticsearch/model/response/suggestions.rb +17 -0
- data/lib/elasticsearch/model/response.rb +17 -0
- data/lib/elasticsearch/model/searching.rb +17 -0
- data/lib/elasticsearch/model/serializing.rb +17 -0
- data/lib/elasticsearch/model/version.rb +18 -1
- data/lib/elasticsearch/model.rb +26 -61
- data/spec/elasticsearch/model/adapter_spec.rb +17 -0
- data/spec/elasticsearch/model/adapters/active_record/associations_spec.rb +17 -0
- data/spec/elasticsearch/model/adapters/active_record/basic_spec.rb +281 -226
- data/spec/elasticsearch/model/adapters/active_record/dynamic_index_name_spec.rb +17 -0
- data/spec/elasticsearch/model/adapters/active_record/import_spec.rb +17 -0
- data/spec/elasticsearch/model/adapters/active_record/multi_model_spec.rb +17 -0
- data/spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb +18 -1
- data/spec/elasticsearch/model/adapters/active_record/pagination_spec.rb +17 -0
- data/spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb +18 -1
- data/spec/elasticsearch/model/adapters/active_record/serialization_spec.rb +17 -0
- data/spec/elasticsearch/model/adapters/active_record_spec.rb +17 -0
- data/spec/elasticsearch/model/adapters/default_spec.rb +17 -0
- data/spec/elasticsearch/model/adapters/mongoid/basic_spec.rb +17 -0
- data/spec/elasticsearch/model/adapters/mongoid/multi_model_spec.rb +17 -0
- data/spec/elasticsearch/model/adapters/mongoid_spec.rb +17 -0
- data/spec/elasticsearch/model/adapters/multiple_spec.rb +17 -0
- data/spec/elasticsearch/model/callbacks_spec.rb +17 -0
- data/spec/elasticsearch/model/client_spec.rb +17 -0
- data/spec/elasticsearch/model/hash_wrapper_spec.rb +17 -0
- data/spec/elasticsearch/model/importing_spec.rb +17 -0
- data/spec/elasticsearch/model/indexing_spec.rb +111 -15
- data/spec/elasticsearch/model/module_spec.rb +17 -25
- data/spec/elasticsearch/model/multimodel_spec.rb +17 -0
- data/spec/elasticsearch/model/naming_spec.rb +22 -5
- data/spec/elasticsearch/model/proxy_spec.rb +17 -0
- data/spec/elasticsearch/model/response/aggregations_spec.rb +17 -0
- data/spec/elasticsearch/model/response/base_spec.rb +17 -0
- data/spec/elasticsearch/model/response/pagination/kaminari_spec.rb +85 -23
- data/spec/elasticsearch/model/response/pagination/will_paginate_spec.rb +17 -0
- data/spec/elasticsearch/model/response/records_spec.rb +17 -0
- data/spec/elasticsearch/model/response/response_spec.rb +17 -0
- data/spec/elasticsearch/model/response/result_spec.rb +17 -0
- data/spec/elasticsearch/model/response/results_spec.rb +17 -0
- data/spec/elasticsearch/model/searching_search_request_spec.rb +17 -0
- data/spec/elasticsearch/model/searching_spec.rb +17 -0
- data/spec/elasticsearch/model/serializing_spec.rb +17 -0
- data/spec/spec_helper.rb +27 -3
- data/spec/support/app/answer.rb +17 -0
- data/spec/support/app/article.rb +17 -0
- data/spec/support/app/article_for_pagination.rb +17 -0
- data/spec/support/app/article_no_type.rb +37 -0
- data/spec/support/app/article_with_custom_serialization.rb +17 -0
- data/spec/support/app/article_with_dynamic_index_name.rb +17 -0
- data/spec/support/app/author.rb +17 -0
- data/spec/support/app/authorship.rb +17 -0
- data/spec/support/app/category.rb +17 -0
- data/spec/support/app/comment.rb +17 -0
- data/spec/support/app/episode.rb +17 -0
- data/spec/support/app/image.rb +17 -0
- data/spec/support/app/import_article.rb +17 -0
- data/spec/support/app/mongoid_article.rb +17 -0
- data/spec/support/app/namespaced_book.rb +17 -0
- data/spec/support/app/parent_and_child_searchable.rb +21 -4
- data/spec/support/app/post.rb +17 -0
- data/spec/support/app/question.rb +17 -0
- data/spec/support/app/searchable.rb +17 -0
- data/spec/support/app/series.rb +17 -0
- data/spec/support/app.rb +27 -2
- metadata +6 -5
- data/spec/elasticsearch/model/naming_inheritance_spec.rb +0 -184
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
module Elasticsearch
|
|
2
19
|
module Model
|
|
3
20
|
|
|
@@ -75,31 +92,14 @@ module Elasticsearch
|
|
|
75
92
|
private
|
|
76
93
|
|
|
77
94
|
def implicit(prop)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if Elasticsearch::Model.settings[:inheritance_enabled]
|
|
81
|
-
self.ancestors.each do |klass|
|
|
82
|
-
# When Naming is included in Proxy::ClassMethods the actual model
|
|
83
|
-
# is among its ancestors. We don't want to call the actual model
|
|
84
|
-
# since it will result in the same call to the same instance of
|
|
85
|
-
# Proxy::ClassMethods. To prevent this we also skip the ancestor
|
|
86
|
-
# that is the target.
|
|
87
|
-
next if klass == self || self.respond_to?(:target) && klass == self.target
|
|
88
|
-
break if value = klass.respond_to?(prop) && klass.send(prop)
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
value || self.send("default_#{prop}")
|
|
95
|
+
self.send("default_#{prop}")
|
|
93
96
|
end
|
|
94
97
|
|
|
95
98
|
def default_index_name
|
|
96
99
|
self.model_name.collection.gsub(/\//, '-')
|
|
97
100
|
end
|
|
98
101
|
|
|
99
|
-
def default_document_type
|
|
100
|
-
DEFAULT_DOC_TYPE
|
|
101
|
-
end
|
|
102
|
-
|
|
102
|
+
def default_document_type; end
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
module InstanceMethods
|
|
@@ -1,16 +1,33 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
module Elasticsearch
|
|
2
19
|
module Model
|
|
3
20
|
|
|
4
21
|
# This module provides a proxy interfacing between the including class and
|
|
5
|
-
#
|
|
22
|
+
# `Elasticsearch::Model`, preventing the pollution of the including class namespace.
|
|
6
23
|
#
|
|
7
24
|
# The only "gateway" between the model and Elasticsearch::Model is the
|
|
8
|
-
#
|
|
25
|
+
# `#__elasticsearch__` class and instance method.
|
|
9
26
|
#
|
|
10
27
|
# The including class must be compatible with
|
|
11
28
|
# [ActiveModel](https://github.com/rails/rails/tree/master/activemodel).
|
|
12
29
|
#
|
|
13
|
-
# @example Include the
|
|
30
|
+
# @example Include the `Elasticsearch::Model` module into an `Article` model
|
|
14
31
|
#
|
|
15
32
|
# class Article < ActiveRecord::Base
|
|
16
33
|
# include Elasticsearch::Model
|
|
@@ -36,21 +53,19 @@ module Elasticsearch
|
|
|
36
53
|
# module and the functionality is accessible via the proxy.
|
|
37
54
|
#
|
|
38
55
|
def self.included(base)
|
|
56
|
+
|
|
39
57
|
base.class_eval do
|
|
40
|
-
|
|
41
|
-
#
|
|
58
|
+
|
|
59
|
+
# `ClassMethodsProxy` instance, accessed as `MyModel.__elasticsearch__`
|
|
42
60
|
def self.__elasticsearch__ &block
|
|
43
61
|
@__elasticsearch__ ||= ClassMethodsProxy.new(self)
|
|
44
62
|
@__elasticsearch__.instance_eval(&block) if block_given?
|
|
45
63
|
@__elasticsearch__
|
|
46
64
|
end
|
|
47
65
|
|
|
48
|
-
#
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
@__elasticsearch__ ||= InstanceMethodsProxy.new(self)
|
|
52
|
-
@__elasticsearch__.instance_eval(&block) if block_given?
|
|
53
|
-
@__elasticsearch__
|
|
66
|
+
# Mix the importing module into the `ClassMethodsProxy`
|
|
67
|
+
self.__elasticsearch__.class_eval do
|
|
68
|
+
include Adapter.from_class(base).importing_mixin
|
|
54
69
|
end
|
|
55
70
|
|
|
56
71
|
# Register a callback for storing changed attributes for models which implement
|
|
@@ -58,18 +73,28 @@ module Elasticsearch
|
|
|
58
73
|
#
|
|
59
74
|
# @see http://api.rubyonrails.org/classes/ActiveModel/Dirty.html
|
|
60
75
|
#
|
|
61
|
-
before_save do |
|
|
62
|
-
if
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
76
|
+
before_save do |obj|
|
|
77
|
+
if obj.respond_to?(:changes_to_save) # Rails 5.1
|
|
78
|
+
changes_to_save = obj.changes_to_save
|
|
79
|
+
elsif obj.respond_to?(:changes)
|
|
80
|
+
changes_to_save = obj.changes
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
if changes_to_save
|
|
84
|
+
attrs = obj.__elasticsearch__.instance_variable_get(:@__changed_model_attributes) || {}
|
|
85
|
+
latest_changes = changes_to_save.inject({}) { |latest_changes, (k,v)| latest_changes.merge!(k => v.last) }
|
|
86
|
+
obj.__elasticsearch__.instance_variable_set(:@__changed_model_attributes, attrs.merge(latest_changes))
|
|
70
87
|
end
|
|
71
88
|
end if respond_to?(:before_save)
|
|
72
89
|
end
|
|
90
|
+
|
|
91
|
+
# {InstanceMethodsProxy}, accessed as `@mymodel.__elasticsearch__`
|
|
92
|
+
#
|
|
93
|
+
def __elasticsearch__ &block
|
|
94
|
+
@__elasticsearch__ ||= InstanceMethodsProxy.new(self)
|
|
95
|
+
@__elasticsearch__.instance_eval(&block) if block_given?
|
|
96
|
+
@__elasticsearch__
|
|
97
|
+
end
|
|
73
98
|
end
|
|
74
99
|
|
|
75
100
|
# @overload dup
|
|
@@ -113,6 +138,11 @@ module Elasticsearch
|
|
|
113
138
|
#
|
|
114
139
|
class ClassMethodsProxy
|
|
115
140
|
include Base
|
|
141
|
+
include Elasticsearch::Model::Client::ClassMethods
|
|
142
|
+
include Elasticsearch::Model::Naming::ClassMethods
|
|
143
|
+
include Elasticsearch::Model::Indexing::ClassMethods
|
|
144
|
+
include Elasticsearch::Model::Searching::ClassMethods
|
|
145
|
+
include Elasticsearch::Model::Importing::ClassMethods
|
|
116
146
|
end
|
|
117
147
|
|
|
118
148
|
# A proxy interfacing between Elasticsearch::Model instance methods and model instance methods
|
|
@@ -121,6 +151,10 @@ module Elasticsearch
|
|
|
121
151
|
#
|
|
122
152
|
class InstanceMethodsProxy
|
|
123
153
|
include Base
|
|
154
|
+
include Elasticsearch::Model::Client::InstanceMethods
|
|
155
|
+
include Elasticsearch::Model::Naming::InstanceMethods
|
|
156
|
+
include Elasticsearch::Model::Indexing::InstanceMethods
|
|
157
|
+
include Elasticsearch::Model::Serializing::InstanceMethods
|
|
124
158
|
|
|
125
159
|
def klass
|
|
126
160
|
target.class
|
|
@@ -136,8 +170,11 @@ module Elasticsearch
|
|
|
136
170
|
def as_json(options={})
|
|
137
171
|
target.as_json(options)
|
|
138
172
|
end
|
|
139
|
-
end
|
|
140
173
|
|
|
174
|
+
def as_indexed_json(options={})
|
|
175
|
+
target.respond_to?(:as_indexed_json) ? target.__send__(:as_indexed_json, options) : super
|
|
176
|
+
end
|
|
177
|
+
end
|
|
141
178
|
end
|
|
142
179
|
end
|
|
143
180
|
end
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
module Elasticsearch
|
|
2
19
|
module Model
|
|
3
20
|
module Response
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
module Elasticsearch
|
|
2
19
|
module Model
|
|
3
20
|
module Response
|
|
@@ -31,7 +48,11 @@ module Elasticsearch
|
|
|
31
48
|
# Returns the total number of hits
|
|
32
49
|
#
|
|
33
50
|
def total
|
|
34
|
-
response.response['hits']['total']
|
|
51
|
+
if response.response['hits']['total'].respond_to?(:keys)
|
|
52
|
+
response.response['hits']['total']['value']
|
|
53
|
+
else
|
|
54
|
+
response.response['hits']['total']
|
|
55
|
+
end
|
|
35
56
|
end
|
|
36
57
|
|
|
37
58
|
# Returns the max_score
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
module Elasticsearch
|
|
2
19
|
module Model
|
|
3
20
|
module Response
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
module Elasticsearch
|
|
2
19
|
module Model
|
|
3
20
|
module Response
|
|
@@ -1,2 +1,19 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
require 'elasticsearch/model/response/pagination/kaminari'
|
|
2
19
|
require 'elasticsearch/model/response/pagination/will_paginate'
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
module Elasticsearch
|
|
2
19
|
module Model
|
|
3
20
|
module Response
|
|
@@ -28,7 +45,6 @@ module Elasticsearch
|
|
|
28
45
|
metaclass.__send__ :include, adapter.records_mixin
|
|
29
46
|
|
|
30
47
|
self.options = options
|
|
31
|
-
self
|
|
32
48
|
end
|
|
33
49
|
|
|
34
50
|
# Returns the hit IDs
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
module Elasticsearch
|
|
2
19
|
module Model
|
|
3
20
|
module Response
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
module Elasticsearch
|
|
2
19
|
module Model
|
|
3
20
|
module Response
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
module Elasticsearch
|
|
2
19
|
module Model
|
|
3
20
|
module Response
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
module Elasticsearch
|
|
2
19
|
module Model
|
|
3
20
|
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
module Elasticsearch
|
|
2
19
|
module Model
|
|
3
20
|
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
module Elasticsearch
|
|
2
19
|
module Model
|
|
3
20
|
|
|
@@ -1,5 +1,22 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
module Elasticsearch
|
|
2
19
|
module Model
|
|
3
|
-
VERSION =
|
|
20
|
+
VERSION = "7.0.0"
|
|
4
21
|
end
|
|
5
22
|
end
|
data/lib/elasticsearch/model.rb
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
require 'hashie/mash'
|
|
2
19
|
|
|
3
20
|
require 'active_support/core_ext/module/delegation'
|
|
@@ -72,9 +89,10 @@ module Elasticsearch
|
|
|
72
89
|
|
|
73
90
|
# Adds the `Elasticsearch::Model` functionality to the including class.
|
|
74
91
|
#
|
|
75
|
-
# * Creates the `__elasticsearch__` class and instance methods
|
|
76
|
-
#
|
|
77
|
-
# *
|
|
92
|
+
# * Creates the `__elasticsearch__` class and instance method. These methods return a proxy object with
|
|
93
|
+
# other common methods defined on them.
|
|
94
|
+
# * The module includes other modules with further functionality.
|
|
95
|
+
# * Sets up delegation for common methods such as `import` and `search`.
|
|
78
96
|
#
|
|
79
97
|
# @example Include the module in the `Article` model definition
|
|
80
98
|
#
|
|
@@ -91,44 +109,16 @@ module Elasticsearch
|
|
|
91
109
|
base.class_eval do
|
|
92
110
|
include Elasticsearch::Model::Proxy
|
|
93
111
|
|
|
94
|
-
|
|
95
|
-
include Elasticsearch::Model::Client::ClassMethods
|
|
96
|
-
include Elasticsearch::Model::Naming::ClassMethods
|
|
97
|
-
include Elasticsearch::Model::Indexing::ClassMethods
|
|
98
|
-
include Elasticsearch::Model::Searching::ClassMethods
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
Elasticsearch::Model::Proxy::InstanceMethodsProxy.class_eval do
|
|
102
|
-
include Elasticsearch::Model::Client::InstanceMethods
|
|
103
|
-
include Elasticsearch::Model::Naming::InstanceMethods
|
|
104
|
-
include Elasticsearch::Model::Indexing::InstanceMethods
|
|
105
|
-
include Elasticsearch::Model::Serializing::InstanceMethods
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
Elasticsearch::Model::Proxy::InstanceMethodsProxy.class_eval <<-CODE, __FILE__, __LINE__ + 1
|
|
109
|
-
def as_indexed_json(options={})
|
|
110
|
-
target.respond_to?(:as_indexed_json) ? target.__send__(:as_indexed_json, options) : super
|
|
111
|
-
end
|
|
112
|
-
CODE
|
|
113
|
-
|
|
114
|
-
# Delegate important methods to the `__elasticsearch__` proxy, unless they are defined already
|
|
115
|
-
#
|
|
112
|
+
# Delegate common methods to the `__elasticsearch__` ClassMethodsProxy, unless they are defined already
|
|
116
113
|
class << self
|
|
117
114
|
METHODS.each do |method|
|
|
118
|
-
delegate method, to: :__elasticsearch__ unless self.
|
|
115
|
+
delegate method, to: :__elasticsearch__ unless self.respond_to?(method)
|
|
119
116
|
end
|
|
120
117
|
end
|
|
121
|
-
|
|
122
|
-
# Mix the importing module into the proxy
|
|
123
|
-
#
|
|
124
|
-
self.__elasticsearch__.class_eval do
|
|
125
|
-
include Elasticsearch::Model::Importing::ClassMethods
|
|
126
|
-
include Adapter.from_class(base).importing_mixin
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
# Add to the registry if it's a class (and not in intermediate module)
|
|
130
|
-
Registry.add(base) if base.is_a?(Class)
|
|
131
118
|
end
|
|
119
|
+
|
|
120
|
+
# Add to the model to the registry if it's a class (and not in intermediate module)
|
|
121
|
+
Registry.add(base) if base.is_a?(Class)
|
|
132
122
|
end
|
|
133
123
|
|
|
134
124
|
module ClassMethods
|
|
@@ -182,36 +172,11 @@ module Elasticsearch
|
|
|
182
172
|
Response::Response.new(models, request)
|
|
183
173
|
end
|
|
184
174
|
|
|
185
|
-
# Check if inheritance is enabled
|
|
186
|
-
#
|
|
187
|
-
# @note Inheritance is disabled by default.
|
|
188
|
-
#
|
|
189
|
-
def inheritance_enabled
|
|
190
|
-
@settings[:inheritance_enabled] ||= false
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
# Enable inheritance of index_name and document_type
|
|
194
|
-
#
|
|
195
|
-
# @example Enable inheritance
|
|
196
|
-
#
|
|
197
|
-
# Elasticsearch::Model.inheritance_enabled = true
|
|
198
|
-
#
|
|
199
|
-
def inheritance_enabled=(inheritance_enabled)
|
|
200
|
-
warn STI_DEPRECATION_WARNING if inheritance_enabled
|
|
201
|
-
@settings[:inheritance_enabled] = inheritance_enabled
|
|
202
|
-
end
|
|
203
|
-
|
|
204
175
|
# Access the module settings
|
|
205
176
|
#
|
|
206
177
|
def settings
|
|
207
178
|
@settings ||= {}
|
|
208
179
|
end
|
|
209
|
-
|
|
210
|
-
private
|
|
211
|
-
|
|
212
|
-
STI_DEPRECATION_WARNING = "DEPRECATION WARNING: Support for Single Table Inheritance (STI) is deprecated " +
|
|
213
|
-
"and will be removed in version 7.0.0.\nPlease save different model documents in separate indices and refer " +
|
|
214
|
-
"to the Elasticsearch documentation for more information.".freeze
|
|
215
180
|
end
|
|
216
181
|
extend ClassMethods
|
|
217
182
|
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
require 'spec_helper'
|
|
2
19
|
|
|
3
20
|
describe Elasticsearch::Model::Adapter do
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
|
3
|
+
# this work for additional information regarding copyright
|
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
|
6
|
+
# not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
|
12
|
+
# software distributed under the License is distributed on an
|
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
14
|
+
# KIND, either express or implied. See the License for the
|
|
15
|
+
# specific language governing permissions and limitations
|
|
16
|
+
# under the License.
|
|
17
|
+
|
|
1
18
|
require 'spec_helper'
|
|
2
19
|
|
|
3
20
|
describe 'Elasticsearch::Model::Adapter::ActiveRecord Associations' do
|