elasticsearch-model 7.0.0.pre → 7.1.2.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: be320b65dde58892add536b616fa70a1bd3ad1be9f4dd4d49d3250fb62d8bb93
4
- data.tar.gz: 27386a4dea06f8ba4cbb6bf926b76315b38b4dff0df55e02a050ffdd54430afc
3
+ metadata.gz: 51e1e98703f1834d64dc969afcc75f107460220a9e213dc128dc5e1015be5a7b
4
+ data.tar.gz: b44da631182388ef384dcab9f6e9d3626c40bf2b6272ef35c6f4857670320f6e
5
5
  SHA512:
6
- metadata.gz: f47057b8d82eb6f49fe7b495806a3b35caa149ebdb3236ed9133d4faad32159e5b47db970e2d6b2488681be4dba5a6f40dc1eec7cfaaee997c428bfb1bd9bb0b
7
- data.tar.gz: b1eb060284f12d714c1a7a32cb3705aeee05eb641fb98fcb269e582eacfa28b7da8449d97fa30d6bf5ec4ad188f5f491250ba81e54bf4fa2b8358af62adac60a
6
+ metadata.gz: a627d5e725a0a3ffb0476873617e0f5d99f297ac1bad49554b69e1546f28bbc58a6cd3b3e54282d0127ed3da828f187f6dba4dc449bbe51ad8229b0b0167a276
7
+ data.tar.gz: 35b7bc2cb6161fff40247e4cf76fd789ffbc12c4c2acfb1e8223b567ce799bcb12a9fd8857cf1bdbdb13999a981114b2e46f6054f5a27dfb1d487cb188f86860
data/Gemfile CHANGED
@@ -21,6 +21,6 @@ source 'https://rubygems.org'
21
21
  gemspec
22
22
 
23
23
  group :development, :testing do
24
- gem 'rspec'
25
24
  gem 'pry-nav'
25
+ gem 'rspec'
26
26
  end
data/README.md CHANGED
@@ -1,25 +1,22 @@
1
1
  # Elasticsearch::Model
2
2
 
3
- The `elasticsearch-model` library builds on top of the
4
- the [`elasticsearch`](https://github.com/elastic/elasticsearch-ruby) library.
3
+ The `elasticsearch-model` library builds on top of the the [`elasticsearch`](https://github.com/elastic/elasticsearch-ruby) library.
5
4
 
6
- It aims to simplify integration of Ruby classes ("models"), commonly found
7
- e.g. in [Ruby on Rails](http://rubyonrails.org) applications, with the
8
- [Elasticsearch](http://www.elasticsearch.org) search and analytics engine.
5
+ It aims to simplify integration of Ruby classes ("models"), commonly found e.g. in [Ruby on Rails](http://rubyonrails.org) applications, with the [Elasticsearch](https://www.elastic.co) search and analytics engine.
9
6
 
10
7
  ## Compatibility
11
8
 
12
- This library is compatible with Ruby 1.9.3 and higher.
9
+ This library is compatible with Ruby 2.4 and higher.
13
10
 
14
- The library version numbers follow the Elasticsearch major versions, and the `master` branch
15
- is compatible with the Elasticsearch `master` branch, therefore, with the next major version.
11
+ The library version numbers follow the Elasticsearch major versions. The `master` branch is compatible with the latest Elasticsearch stack stable release.
16
12
 
17
13
  | Rubygem | | Elasticsearch |
18
14
  |:-------------:|:-:| :-----------: |
19
15
  | 0.1 | → | 1.x |
20
16
  | 2.x | → | 2.x |
21
17
  | 5.x | → | 5.x |
22
- | master | → | master |
18
+ | 6.x | → | 6.x |
19
+ | master | → | 7.x |
23
20
 
24
21
  ## Installation
25
22
 
@@ -72,9 +69,7 @@ This will extend the model with functionality related to Elasticsearch.
72
69
 
73
70
  #### Feature Extraction Pattern
74
71
 
75
- Instead of including the `Elasticsearch::Model` module directly in your model,
76
- you can include it in a "concern" or "trait" module, which is quite common pattern in Rails applications,
77
- using e.g. `ActiveSupport::Concern` as the instrumentation:
72
+ Instead of including the `Elasticsearch::Model` module directly in your model, you can include it in a "concern" or "trait" module, which is quite common pattern in Rails applications, using e.g. `ActiveSupport::Concern` as the instrumentation:
78
73
 
79
74
  ```ruby
80
75
  # In: app/models/concerns/searchable.rb
@@ -151,7 +146,7 @@ for information about the Ruby client API.
151
146
 
152
147
  ### Importing the data
153
148
 
154
- The first thing you'll want to do is importing your data into the index:
149
+ The first thing you'll want to do is import your data into the index:
155
150
 
156
151
  ```ruby
157
152
  Article.import
@@ -289,11 +284,8 @@ NOTE: It is _not_ possible to chain other methods on top of the `records` object
289
284
 
290
285
  #### Pagination
291
286
 
292
- You can implement pagination with the `from` and `size` search parameters. However, search results
293
- can be automatically paginated with the [`kaminari`](http://rubygems.org/gems/kaminari) or
294
- [`will_paginate`](https://github.com/mislav/will_paginate) gems.
295
- (The pagination gems must be added before the Elasticsearch gems in your Gemfile,
296
- or loaded first in your application.)
287
+ You can implement pagination with the `from` and `size` search parameters. However, search results can be automatically paginated with the [`kaminari`](http://rubygems.org/gems/kaminari) or [`will_paginate`](https://github.com/mislav/will_paginate) gems.
288
+ (The pagination gems must be added before the Elasticsearch gems in your Gemfile, or loaded first in your application.)
297
289
 
298
290
  If Kaminari or WillPaginate is loaded, use the familiar paging methods:
299
291
 
@@ -321,8 +313,7 @@ Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model
321
313
 
322
314
  #### The Elasticsearch DSL
323
315
 
324
- In most situations, you'll want to pass the search definition
325
- in the Elasticsearch [domain-specific language](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl.html) to the client:
316
+ In most situations, you'll want to pass the search definition in the Elasticsearch [domain-specific language](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html) to the client:
326
317
 
327
318
  ```ruby
328
319
  response = Article.search query: { match: { title: "Fox Dogs" } },
@@ -332,8 +323,7 @@ response.results.first.highlight.title
332
323
  # ["Quick brown <em>fox</em>"]
333
324
  ```
334
325
 
335
- You can pass any object which implements a `to_hash` method, which is called automatically,
336
- so you can use a custom class or your favourite JSON builder to build the search definition:
326
+ You can pass any object which implements a `to_hash` method, which is called automatically, so you can use a custom class or your favourite JSON builder to build the search definition:
337
327
 
338
328
  ```ruby
339
329
  require 'jbuilder'
@@ -353,8 +343,7 @@ response.results.first.title
353
343
  # => "Quick brown fox"
354
344
  ```
355
345
 
356
- Also, you can use the [**`elasticsearch-dsl`**](https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-dsl) library, which provides a specialized Ruby API for
357
- the Elasticsearch Query DSL:
346
+ Also, you can use the [**`elasticsearch-dsl`**](https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-dsl) library, which provides a specialized Ruby API for the Elasticsearch Query DSL:
358
347
 
359
348
  ```ruby
360
349
  require 'elasticsearch/dsl'
@@ -732,13 +721,8 @@ module and its submodules for technical information.
732
721
 
733
722
  The module provides a common `settings` method to customize various features.
734
723
 
735
- At the moment, the only supported setting is `:inheritance_enabled`, which makes the class receiving the module
736
- respect index names and document types of a super-class, eg. in case you're using "single table inheritance" (STI)
737
- in Rails:
738
-
739
- ```ruby
740
- Elasticsearch::Model.settings[:inheritance_enabled] = true
741
- ```
724
+ Before version 7.0.0 of the gem, the only supported setting was `:inheritance_enabled`. This setting has been deprecated
725
+ and removed.
742
726
 
743
727
  ## Development and Community
744
728
 
@@ -756,20 +740,34 @@ curl -# https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticse
756
740
  SERVER=start TEST_CLUSTER_COMMAND=$PWD/tmp/elasticsearch-1.0.0.RC1/bin/elasticsearch bundle exec rake test:all
757
741
  ```
758
742
 
743
+ ### Single Table Inheritance support
744
+
745
+ Versions < 7.0.0 of this gem supported inheritance-- more specifically, `Single Table Inheritance`. With this feature,
746
+ elasticsearch settings (index mappings, etc) on a parent model could be inherited by a child model leading to different
747
+ model documents being indexed into the same Elasticsearch index. This feature depended on the ability to set a `type`
748
+ for a document in Elasticsearch. The Elasticsearch team has deprecated support for `types`, as is described
749
+ [here.](https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html)
750
+ This gem will also remove support for types and `Single Table Inheritance` in version 7.0 as it enables an anti-pattern.
751
+ Please save different model documents in separate indices. If you want to use STI, you can include an artificial
752
+ `type` field manually in each document and use it in other operations.
753
+
759
754
  ## License
760
755
 
761
756
  This software is licensed under the Apache 2 license, quoted below.
762
757
 
763
- Copyright (c) 2014 Elasticsearch <http://www.elasticsearch.org>
764
-
765
- Licensed under the Apache License, Version 2.0 (the "License");
766
- you may not use this file except in compliance with the License.
758
+ Licensed to Elasticsearch B.V. under one or more contributor
759
+ license agreements. See the NOTICE file distributed with
760
+ this work for additional information regarding copyright
761
+ ownership. Elasticsearch B.V. licenses this file to you under
762
+ the Apache License, Version 2.0 (the "License"); you may
763
+ not use this file except in compliance with the License.
767
764
  You may obtain a copy of the License at
768
-
769
- http://www.apache.org/licenses/LICENSE-2.0
770
-
771
- Unless required by applicable law or agreed to in writing, software
772
- distributed under the License is distributed on an "AS IS" BASIS,
773
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
774
- See the License for the specific language governing permissions and
775
- limitations under the License.
765
+
766
+ http://www.apache.org/licenses/LICENSE-2.0
767
+
768
+ Unless required by applicable law or agreed to in writing,
769
+ software distributed under the License is distributed on an
770
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
771
+ KIND, either express or implied. See the License for the
772
+ specific language governing permissions and limitations
773
+ under the License.
data/Rakefile CHANGED
@@ -15,17 +15,15 @@
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 = ['5.0.gemfile', '6.0.gemfile']
25
+ gemfiles << '4.0.gemfile' if RUBY_VERSION < '2.7'
26
+ GEMFILES = gemfiles.freeze
29
27
 
30
28
  namespace :bundle do
31
29
  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 +45,6 @@ end
47
45
 
48
46
  require 'rake/testtask'
49
47
  namespace :test do
50
-
51
48
  desc 'Run all tests. Optionally define env variable RAILS_VERSIONS. E.g. RAILS_VERSIONS=3.0,5.0'
52
49
  task :all, [:rails_versions] do |task, args|
53
50
  gemfiles = ENV['RAILS_VERSIONS'] ? ENV['RAILS_VERSIONS'].split(',').map {|v| "#{v}.gemfile"} : GEMFILES
@@ -16,56 +16,54 @@
16
16
  # under the License.
17
17
 
18
18
  # coding: utf-8
19
- lib = File.expand_path('../lib', __FILE__)
19
+
20
+ lib = File.expand_path('lib', __dir__)
20
21
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
21
22
  require 'elasticsearch/model/version'
22
23
 
23
24
  Gem::Specification.new do |s|
24
- s.name = "elasticsearch-model"
25
+ s.name = 'elasticsearch-model'
25
26
  s.version = Elasticsearch::Model::VERSION
26
- s.authors = ["Karel Minarik"]
27
- s.email = ["karel.minarik@elasticsearch.org"]
28
- s.description = "ActiveModel/Record integrations for Elasticsearch."
29
- s.summary = "ActiveModel/Record integrations for Elasticsearch."
30
- s.homepage = "https://github.com/elasticsearch/elasticsearch-rails/"
31
- s.license = "Apache 2"
27
+ s.authors = ['Karel Minarik']
28
+ s.email = ['karel.minarik@elasticsearch.org']
29
+ s.description = 'ActiveModel/Record integrations for Elasticsearch.'
30
+ s.summary = 'ActiveModel/Record integrations for Elasticsearch.'
31
+ s.homepage = 'https://github.com/elasticsearch/elasticsearch-rails/'
32
+ s.license = 'Apache 2'
32
33
 
33
34
  s.files = `git ls-files`.split($/)
34
35
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
35
36
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
36
- s.require_paths = ["lib"]
37
-
38
- s.extra_rdoc_files = [ "README.md", "LICENSE.txt" ]
39
- s.rdoc_options = [ "--charset=UTF-8" ]
40
-
41
- s.required_ruby_version = ">= 1.9.3"
42
-
43
- s.add_dependency "elasticsearch", '> 1'
44
- s.add_dependency "activesupport", '> 3'
45
- s.add_dependency "hashie"
46
-
47
- s.add_development_dependency "bundler"
48
- s.add_development_dependency "rake", "~> 11.1"
49
-
50
- s.add_development_dependency "elasticsearch-extensions"
37
+ s.require_paths = ['lib']
51
38
 
52
- s.add_development_dependency "sqlite3" unless defined?(JRUBY_VERSION)
53
- s.add_development_dependency "activemodel", "> 3"
39
+ s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
40
+ s.rdoc_options = ['--charset=UTF-8']
54
41
 
55
- s.add_development_dependency "oj" unless defined?(JRUBY_VERSION)
56
- s.add_development_dependency "kaminari"
57
- s.add_development_dependency "will_paginate"
42
+ s.required_ruby_version = '>= 2.4'
58
43
 
59
- s.add_development_dependency "minitest"
60
- s.add_development_dependency "test-unit"
61
- s.add_development_dependency "shoulda-context"
62
- s.add_development_dependency "mocha"
63
- s.add_development_dependency "turn"
64
- s.add_development_dependency "yard"
65
- s.add_development_dependency "ruby-prof" unless defined?(JRUBY_VERSION)
66
- s.add_development_dependency "pry"
44
+ s.add_dependency 'activesupport', '> 3'
45
+ s.add_dependency 'elasticsearch', '~> 7'
46
+ s.add_dependency 'hashie'
67
47
 
68
- s.add_development_dependency "simplecov"
69
- s.add_development_dependency "cane"
70
- s.add_development_dependency "require-prof"
48
+ s.add_development_dependency 'activemodel', '> 3'
49
+ s.add_development_dependency 'bundler'
50
+ s.add_development_dependency 'cane'
51
+ s.add_development_dependency 'elasticsearch-extensions'
52
+ s.add_development_dependency 'kaminari'
53
+ s.add_development_dependency 'minitest'
54
+ s.add_development_dependency 'mocha'
55
+ s.add_development_dependency 'pry'
56
+ s.add_development_dependency 'rake', '~> 12'
57
+ s.add_development_dependency 'require-prof'
58
+ s.add_development_dependency 'shoulda-context'
59
+ s.add_development_dependency 'simplecov'
60
+ s.add_development_dependency 'test-unit'
61
+ s.add_development_dependency 'turn'
62
+ s.add_development_dependency 'will_paginate'
63
+ s.add_development_dependency 'yard'
64
+ unless defined?(JRUBY_VERSION)
65
+ s.add_development_dependency 'oj'
66
+ s.add_development_dependency 'ruby-prof'
67
+ s.add_development_dependency 'sqlite3'
68
+ end
71
69
  end
@@ -98,6 +98,22 @@ module Searchable
98
98
 
99
99
  module Indexing
100
100
 
101
+ #Index only the specified fields
102
+ settings do
103
+ mappings dynamic: false do
104
+ indexes :categories, type: :object do
105
+ indexes :title
106
+ end
107
+ indexes :authors, type: :object do
108
+ indexes :full_name
109
+ indexes :department
110
+ end
111
+ indexes :comments, type: :object do
112
+ indexes :text
113
+ end
114
+ end
115
+ end
116
+
101
117
  # Customize the JSON serialization for Elasticsearch
102
118
  def as_indexed_json(options={})
103
119
  self.as_json(
data/gemfiles/4.0.gemfile CHANGED
@@ -26,10 +26,11 @@ gemspec path: '../'
26
26
 
27
27
  gem 'activemodel', '~> 4'
28
28
  gem 'activerecord', '~> 4'
29
- gem 'sqlite3', '> 1.3', '< 1.4' unless defined?(JRUBY_VERSION)
30
29
  gem 'mongoid', '~> 5'
30
+ gem 'sqlite3', '> 1.3', '< 1.4' unless defined?(JRUBY_VERSION)
31
31
 
32
32
  group :development, :testing do
33
- gem 'rspec'
33
+ gem 'bigdecimal', '~> 1'
34
34
  gem 'pry-nav'
35
- end
35
+ gem 'rspec'
36
+ end
data/gemfiles/6.0.gemfile CHANGED
@@ -25,10 +25,10 @@ source 'https://rubygems.org'
25
25
 
26
26
  gemspec path: '../'
27
27
 
28
- gem 'activemodel', '6.0.0.rc1'
29
- gem 'activerecord', '6.0.0.rc1'
28
+ gem 'activemodel', '6.0.0'
29
+ gem 'activerecord', '6.0.0'
30
30
  gem 'sqlite3' unless defined?(JRUBY_VERSION)
31
- gem 'mongoid', '~> 6'
31
+ #gem 'mongoid', '~> 6'
32
32
 
33
33
  group :development, :testing do
34
34
  gem 'rspec'
@@ -89,9 +89,10 @@ module Elasticsearch
89
89
 
90
90
  # Adds the `Elasticsearch::Model` functionality to the including class.
91
91
  #
92
- # * Creates the `__elasticsearch__` class and instance methods, pointing to the proxy object
93
- # * Includes the necessary modules in the proxy classes
94
- # * Sets up delegation for crucial methods such as `search`, etc.
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`.
95
96
  #
96
97
  # @example Include the module in the `Article` model definition
97
98
  #
@@ -108,50 +109,16 @@ module Elasticsearch
108
109
  base.class_eval do
109
110
  include Elasticsearch::Model::Proxy
110
111
 
111
- Elasticsearch::Model::Proxy::ClassMethodsProxy.class_eval do
112
- include Elasticsearch::Model::Client::ClassMethods
113
- include Elasticsearch::Model::Naming::ClassMethods
114
- include Elasticsearch::Model::Indexing::ClassMethods
115
- include Elasticsearch::Model::Searching::ClassMethods
116
- end
117
-
118
- Elasticsearch::Model::Proxy::InstanceMethodsProxy.class_eval do
119
- include Elasticsearch::Model::Client::InstanceMethods
120
- include Elasticsearch::Model::Naming::InstanceMethods
121
- include Elasticsearch::Model::Indexing::InstanceMethods
122
- include Elasticsearch::Model::Serializing::InstanceMethods
123
- end
124
-
125
- Elasticsearch::Model::Proxy::InstanceMethodsProxy.class_eval <<-CODE, __FILE__, __LINE__ + 1
126
- def as_indexed_json(options={})
127
- target.respond_to?(:as_indexed_json) ? target.__send__(:as_indexed_json, options) : super
128
- end
129
- CODE
130
-
131
- # Delegate important methods to the `__elasticsearch__` proxy, unless they are defined already
132
- #
112
+ # Delegate common methods to the `__elasticsearch__` ClassMethodsProxy, unless they are defined already
133
113
  class << self
134
114
  METHODS.each do |method|
135
115
  delegate method, to: :__elasticsearch__ unless self.public_instance_methods.include?(method)
136
116
  end
137
117
  end
138
-
139
- # Mix the importing module into the proxy
140
- #
141
- self.__elasticsearch__.class_eval do
142
- include Elasticsearch::Model::Importing::ClassMethods
143
- include Adapter.from_class(base).importing_mixin
144
- end
145
-
146
- # Add to the registry if it's a class (and not in intermediate module)
147
- Registry.add(base) if base.is_a?(Class)
148
118
  end
149
- end
150
119
 
151
- # Access the module settings
152
- #
153
- def self.settings
154
- @settings ||= {}
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)
155
122
  end
156
123
 
157
124
  module ClassMethods
@@ -205,22 +172,10 @@ module Elasticsearch
205
172
  Response::Response.new(models, request)
206
173
  end
207
174
 
208
- # Check if inheritance is enabled
209
- #
210
- # @note Inheritance is disabled by default.
211
- #
212
- def inheritance_enabled
213
- @inheritance_enabled ||= false
214
- end
215
-
216
- # Enable inheritance of index_name and document_type
217
- #
218
- # @example Enable inheritance
219
- #
220
- # Elasticsearch::Model.inheritance_enabled = true
175
+ # Access the module settings
221
176
  #
222
- def inheritance_enabled=(inheritance_enabled)
223
- @inheritance_enabled = inheritance_enabled
177
+ def settings
178
+ @settings ||= {}
224
179
  end
225
180
  end
226
181
  extend ClassMethods