elasticsearch-model 7.2.1 → 8.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/README.md +19 -19
  4. data/Rakefile +7 -6
  5. data/elasticsearch-model.gemspec +4 -4
  6. data/examples/activerecord_associations.rb +1 -1
  7. data/examples/activerecord_custom_analyzer.rb +2 -2
  8. data/gemfiles/{6.0.gemfile → 6.1.gemfile} +5 -5
  9. data/gemfiles/{5.0.gemfile → 7.0.gemfile} +7 -6
  10. data/gemfiles/{3.0.gemfile → 7.1.gemfile} +9 -8
  11. data/lib/elasticsearch/model/adapter.rb +0 -2
  12. data/lib/elasticsearch/model/adapters/active_record.rb +0 -4
  13. data/lib/elasticsearch/model/adapters/default.rb +0 -4
  14. data/lib/elasticsearch/model/adapters/mongoid.rb +9 -11
  15. data/lib/elasticsearch/model/adapters/multiple.rb +0 -1
  16. data/lib/elasticsearch/model/importing.rb +1 -12
  17. data/lib/elasticsearch/model/indexing.rb +6 -19
  18. data/lib/elasticsearch/model/multimodel.rb +1 -10
  19. data/lib/elasticsearch/model/naming.rb +7 -58
  20. data/lib/elasticsearch/model/proxy.rb +1 -5
  21. data/lib/elasticsearch/model/response/result.rb +0 -6
  22. data/lib/elasticsearch/model/searching.rb +2 -3
  23. data/lib/elasticsearch/model/version.rb +1 -1
  24. data/lib/elasticsearch/model.rb +1 -3
  25. data/spec/elasticsearch/model/adapter_spec.rb +0 -11
  26. data/spec/elasticsearch/model/adapters/active_record/associations_spec.rb +48 -76
  27. data/spec/elasticsearch/model/adapters/active_record/basic_spec.rb +6 -78
  28. data/spec/elasticsearch/model/adapters/active_record/import_spec.rb +6 -2
  29. data/spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb +1 -5
  30. data/spec/elasticsearch/model/adapters/active_record/pagination_spec.rb +0 -8
  31. data/spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb +1 -4
  32. data/spec/elasticsearch/model/adapters/active_record/serialization_spec.rb +9 -11
  33. data/spec/elasticsearch/model/adapters/mongoid_spec.rb +1 -1
  34. data/spec/elasticsearch/model/adapters/multiple_spec.rb +1 -11
  35. data/spec/elasticsearch/model/importing_spec.rb +6 -35
  36. data/spec/elasticsearch/model/indexing_spec.rb +45 -170
  37. data/spec/elasticsearch/model/module_spec.rb +0 -1
  38. data/spec/elasticsearch/model/multimodel_spec.rb +2 -8
  39. data/spec/elasticsearch/model/naming_spec.rb +0 -68
  40. data/spec/elasticsearch/model/proxy_spec.rb +3 -5
  41. data/spec/elasticsearch/model/response/aggregations_spec.rb +4 -4
  42. data/spec/elasticsearch/model/response/base_spec.rb +0 -1
  43. data/spec/elasticsearch/model/response/pagination/kaminari_spec.rb +3 -4
  44. data/spec/elasticsearch/model/response/pagination/will_paginate_spec.rb +0 -1
  45. data/spec/elasticsearch/model/response/records_spec.rb +0 -1
  46. data/spec/elasticsearch/model/response/response_spec.rb +0 -1
  47. data/spec/elasticsearch/model/response/result_spec.rb +0 -17
  48. data/spec/elasticsearch/model/response/results_spec.rb +0 -1
  49. data/spec/elasticsearch/model/searching_search_request_spec.rb +5 -6
  50. data/spec/spec_helper.rb +9 -11
  51. data/spec/support/app/answer.rb +0 -1
  52. data/spec/support/app/article.rb +0 -2
  53. data/spec/support/app/article_no_type.rb +1 -1
  54. data/spec/support/app/namespaced_book.rb +0 -2
  55. data/spec/support/app/parent_and_child_searchable.rb +6 -4
  56. data/spec/support/app/question.rb +0 -1
  57. metadata +11 -12
  58. data/gemfiles/4.0.gemfile +0 -36
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1aecf263867f2176d7819eccd7e23f9b37bc85132223b8f64398ab85736ea75
4
- data.tar.gz: af80ff000fcf065f2694141bfcdc282a947cfea05f5ece2f11a24897f5753039
3
+ metadata.gz: 0c760a3ffa71e37511564ccafa368fbaf6c7bb8329c0a472c9e1ef9b26739740
4
+ data.tar.gz: 1ded565b299e1a95f35315bdff3645b564d401f2970943ad8c5445d6ee39e1ea
5
5
  SHA512:
6
- metadata.gz: 246ae4f642a662a4a0c5fe6e26581c052c15ddf868d9b47b640c3f996e584056a8facc4004d61151647e67e6624d1bb16cad90a4513f303ad0afdeaf84b1eedf
7
- data.tar.gz: 406c37164bb6fc16068d2edcf6e1183d9c2ba34420d57fab9d3f288416fd0d75173ecc4ad3f37236051d517db717c4fb37ae2d44663f87a6b28213637ea8f7a5
6
+ metadata.gz: a5fca8875b77ac7c26a9bb42802bca17bc88837c356a9ae83ca4404ea4779ad8bd2dc3c039332075a68a17cbfb5f815a34eacc93648dc70f50a42c12aea9026d
7
+ data.tar.gz: 1d56f2c15d073532f89c31b78ccdeabc84ec1dc7dc501728770eea544f9ceb4e8d126570c8593e23dfb381f5249645de6ed0cecb288dbdf67de886e4ad200f45
data/Gemfile CHANGED
@@ -21,6 +21,7 @@ source 'https://rubygems.org'
21
21
  gemspec
22
22
 
23
23
  group :development, :testing do
24
+ gem 'debug' unless defined?(JRUBY_VERSION)
24
25
  gem 'pry-nav'
25
26
  gem 'rspec'
26
27
  end
data/README.md CHANGED
@@ -6,17 +6,19 @@ It aims to simplify integration of Ruby classes ("models"), commonly found e.g.
6
6
 
7
7
  ## Compatibility
8
8
 
9
- This library is compatible with Ruby 2.4 and higher.
9
+ This library is compatible with Ruby 3 and higher.
10
10
 
11
- The library version numbers follow the Elasticsearch major versions. The `main` branch is compatible with the latest Elasticsearch stack stable release.
11
+ The version numbers follow the Elasticsearch major versions. Currently the `main` branch is compatible with version `7.x` of the Elasticsearch stack. **We haven't tested and updated the code for Elasticsearch `8.0` yet**.
12
12
 
13
- | Rubygem | | Elasticsearch |
14
- |:-------------:|:-:| :-----------: |
15
- | 0.1 | → | 1.x |
16
- | 2.x | → | 2.x |
17
- | 5.x | → | 5.x |
18
- | 6.x | → | 6.x |
19
- | main | → | 7.x |
13
+ | Rubygem | | Elasticsearch |
14
+ |:-------:|:-:|:-------------:|
15
+ | 0.1 | → | 1.x |
16
+ | 2.x | → | 2.x |
17
+ | 5.x | → | 5.x |
18
+ | 6.x | → | 6.x |
19
+ | 7.x | → | 7.x |
20
+ | 8.x | → | 8.x |
21
+ | main | → | 8.x |
20
22
 
21
23
  ## Installation
22
24
 
@@ -267,8 +269,8 @@ It is possible to search across multiple models with the module method:
267
269
  ```ruby
268
270
  Elasticsearch::Model.search('fox', [Article, Comment]).results.to_a.map(&:to_hash)
269
271
  # => [
270
- # {"_index"=>"articles", "_type"=>"article", "_id"=>"1", "_score"=>0.35136628, "_source"=>...},
271
- # {"_index"=>"comments", "_type"=>"comment", "_id"=>"1", "_score"=>0.35136628, "_source"=>...}
272
+ # {"_index"=>"articles", "_id"=>"1", "_score"=>0.35136628, "_source"=>...},
273
+ # {"_index"=>"comments", "_id"=>"1", "_score"=>0.35136628, "_source"=>...}
272
274
  # ]
273
275
 
274
276
  Elasticsearch::Model.search('fox', [Article, Comment]).records.to_a
@@ -343,7 +345,7 @@ response.results.first.title
343
345
  # => "Quick brown fox"
344
346
  ```
345
347
 
346
- Also, you can use the [**`elasticsearch-dsl`**](https://github.com/elastic/elasticsearch-ruby/tree/main/elasticsearch-dsl) library, which provides a specialized Ruby API for the Elasticsearch Query DSL:
348
+ Also, you can use the [**`elasticsearch-dsl`**](https://github.com/elastic/elasticsearch-dsl-ruby) library, which provides a specialized Ruby API for the Elasticsearch Query DSL:
347
349
 
348
350
  ```ruby
349
351
  require 'elasticsearch/dsl'
@@ -413,13 +415,11 @@ Article.__elasticsearch__.create_index! force: true
413
415
  Article.__elasticsearch__.refresh_index!
414
416
  ```
415
417
 
416
- By default, index name and document type will be inferred from your class name,
417
- you can set it explicitly, however:
418
+ By default, index name will be inferred from your class name, you can set it explicitly, however:
418
419
 
419
420
  ```ruby
420
421
  class Article
421
422
  index_name "articles-#{Rails.env}"
422
- document_type "post"
423
423
  end
424
424
  ```
425
425
 
@@ -527,11 +527,11 @@ class Indexer
527
527
  case operation.to_s
528
528
  when /index/
529
529
  record = Article.find(record_id)
530
- Client.index index: 'articles', type: 'article', id: record.id, body: record.__elasticsearch__.as_indexed_json
530
+ Client.index index: 'articles', id: record.id, body: record.__elasticsearch__.as_indexed_json
531
531
  when /delete/
532
532
  begin
533
- Client.delete index: 'articles', type: 'article', id: record_id
534
- rescue Elasticsearch::Transport::Transport::Errors::NotFound
533
+ Client.delete index: 'articles', id: record_id
534
+ rescue Elastic::Transport::Transport::Errors::NotFound
535
535
  logger.debug "Article not found, ID: #{record_id}"
536
536
  end
537
537
  else raise ArgumentError, "Unknown operation '#{operation}'"
@@ -553,7 +553,7 @@ You'll see the job being processed in the console where you started the _Sidekiq
553
553
  Indexer JID-eb7e2daf389a1e5e83697128 DEBUG: ["index", "ID: 7"]
554
554
  Indexer JID-eb7e2daf389a1e5e83697128 INFO: PUT http://localhost:9200/articles/article/1 [status:200, request:0.004s, query:n/a]
555
555
  Indexer JID-eb7e2daf389a1e5e83697128 DEBUG: > {"id":1,"title":"Updated", ...}
556
- Indexer JID-eb7e2daf389a1e5e83697128 DEBUG: < {"ok":true,"_index":"articles","_type":"article","_id":"1","_version":6}
556
+ Indexer JID-eb7e2daf389a1e5e83697128 DEBUG: < {"ok":true,"_index":"articles","_id":"1","_version":6}
557
557
  Indexer JID-eb7e2daf389a1e5e83697128 INFO: done: 0.006 sec
558
558
  ```
559
559
 
data/Rakefile CHANGED
@@ -21,8 +21,7 @@ desc 'Run unit tests'
21
21
  task default: 'test:all'
22
22
  task test: 'test:all'
23
23
 
24
- gemfiles = ['5.0.gemfile', '6.0.gemfile']
25
- gemfiles << '4.0.gemfile' if RUBY_VERSION < '2.7'
24
+ gemfiles = ['6.1.gemfile', '7.0.gemfile']
26
25
  GEMFILES = gemfiles.freeze
27
26
 
28
27
  namespace :bundle do
@@ -47,16 +46,18 @@ end
47
46
  require 'rake/testtask'
48
47
  namespace :test do
49
48
  desc 'Run all tests. Optionally define env variable RAILS_VERSIONS. E.g. RAILS_VERSIONS=3.0,5.0'
50
- task :all, [:rails_versions] do |task, args|
51
- gemfiles = ENV['RAILS_VERSIONS'] ? ENV['RAILS_VERSIONS'].split(',').map {|v| "#{v}.gemfile"} : GEMFILES
49
+ task :all do |task, args|
50
+ gemfiles = ENV['RAILS_VERSIONS'] ? ENV['RAILS_VERSIONS'].split(',').map { |v| "#{v}.gemfile" } : GEMFILES
52
51
  puts '-' * 80
53
52
  gemfiles.each do |gemfile|
54
53
  puts "GEMFILE: #{gemfile}"
55
- sh "BUNDLE_GEMFILE='#{File.expand_path("../gemfiles/#{gemfile}", __FILE__)}' " +
56
- " bundle exec rspec"
54
+ sh "BUNDLE_GEMFILE='#{File.expand_path("../gemfiles/#{gemfile}", __FILE__)}' " \
55
+ ' bundle exec rspec'
57
56
  puts '-' * 80
58
57
  end
59
58
  end
59
+
60
+ task unit: :all
60
61
  end
61
62
 
62
63
  # ----- Documentation tasks ---------------------------------------------------
@@ -24,8 +24,8 @@ require 'elasticsearch/model/version'
24
24
  Gem::Specification.new do |s|
25
25
  s.name = 'elasticsearch-model'
26
26
  s.version = Elasticsearch::Model::VERSION
27
- s.authors = ['Karel Minarik']
28
- s.email = ['karel.minarik@elasticsearch.org']
27
+ s.authors = ['Elastic Client Library Maintainers']
28
+ s.email = ['client-libs@elastic.co']
29
29
  s.description = 'ActiveModel/Record integrations for Elasticsearch.'
30
30
  s.summary = 'ActiveModel/Record integrations for Elasticsearch.'
31
31
  s.homepage = 'https://github.com/elasticsearch/elasticsearch-rails/'
@@ -39,10 +39,10 @@ Gem::Specification.new do |s|
39
39
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
40
40
  s.rdoc_options = ['--charset=UTF-8']
41
41
 
42
- s.required_ruby_version = '>= 2.4'
42
+ s.required_ruby_version = '>= 3'
43
43
 
44
44
  s.add_dependency 'activesupport', '> 3'
45
- s.add_dependency 'elasticsearch', '~> 7'
45
+ s.add_dependency 'elasticsearch', '~> 8'
46
46
  s.add_dependency 'hashie'
47
47
 
48
48
  s.add_development_dependency 'activemodel', '> 3'
@@ -81,7 +81,7 @@ end
81
81
  # ----- Elasticsearch client setup ----------------------------------------------------------------
82
82
 
83
83
  Elasticsearch::Model.client = Elasticsearch::Client.new log: true
84
- Elasticsearch::Model.client.transport.transport.logger.formatter = proc { |s, d, p, m| "\e[2m#{m}\n\e[0m" }
84
+ Elasticsearch::Model.client.transport.logger.formatter = proc { |s, d, p, m| "\e[2m#{m}\n\e[0m" }
85
85
 
86
86
  # ----- Search integration ------------------------------------------------------------------------
87
87
 
@@ -37,8 +37,8 @@ ActiveRecord::Schema.define(version: 1) do
37
37
  end
38
38
  end
39
39
 
40
- Elasticsearch::Model.client.transport.transport.logger = ActiveSupport::Logger.new(STDOUT)
41
- Elasticsearch::Model.client.transport.transport.logger.formatter = lambda { |s, d, p, m| "#{m.ansi(:faint)}\n" }
40
+ Elasticsearch::Model.client.transport.logger = ActiveSupport::Logger.new(STDOUT)
41
+ Elasticsearch::Model.client.transport.logger.formatter = lambda { |s, d, p, m| "#{m.ansi(:faint)}\n" }
42
42
 
43
43
  class Article < ActiveRecord::Base
44
44
  include Elasticsearch::Model
@@ -20,17 +20,17 @@
20
20
  # $ BUNDLE_GEMFILE=./gemfiles/6.0.gemfile bundle install
21
21
  # $ BUNDLE_GEMFILE=./gemfiles/6.0.gemfile bundle exec rake test:integration
22
22
 
23
-
24
23
  source 'https://rubygems.org'
25
24
 
26
25
  gemspec path: '../'
27
26
 
28
- gem 'activemodel', '6.0.0'
29
- gem 'activerecord', '6.0.0'
27
+ gem 'activemodel', '6.1'
28
+ gem 'activerecord', '6.1'
30
29
  gem 'sqlite3' unless defined?(JRUBY_VERSION)
31
- #gem 'mongoid', '~> 6'
30
+ # gem 'mongoid', '~> 6'
32
31
 
33
32
  group :development, :testing do
34
- gem 'rspec'
33
+ gem 'debug'
35
34
  gem 'pry-nav'
35
+ gem 'rspec'
36
36
  end
@@ -17,19 +17,20 @@
17
17
 
18
18
  # Usage:
19
19
  #
20
- # $ BUNDLE_GEMFILE=./gemfiles/5.0.gemfile bundle install
21
- # $ BUNDLE_GEMFILE=./gemfiles/5.0.gemfile bundle exec rake test:integration
20
+ # $ BUNDLE_GEMFILE=./gemfiles/7.0.gemfile bundle install
21
+ # $ BUNDLE_GEMFILE=./gemfiles/7.0.gemfile bundle exec rake test:integration
22
22
 
23
23
  source 'https://rubygems.org'
24
24
 
25
25
  gemspec path: '../'
26
26
 
27
- gem 'activemodel', '~> 5'
28
- gem 'activerecord', '~> 5'
27
+ gem 'activemodel', '~> 7'
28
+ gem 'activerecord', '~> 7'
29
29
  gem 'sqlite3' unless defined?(JRUBY_VERSION)
30
- gem 'mongoid', '~> 6'
30
+ # gem 'mongoid', '~> 6'
31
31
 
32
32
  group :development, :testing do
33
- gem 'rspec'
33
+ gem 'debug'
34
34
  gem 'pry-nav'
35
+ gem 'rspec'
35
36
  end
@@ -17,19 +17,20 @@
17
17
 
18
18
  # Usage:
19
19
  #
20
- # $ BUNDLE_GEMFILE=./gemfiles/3.0.gemfile bundle install
21
- # $ BUNDLE_GEMFILE=./gemfiles/3.0.gemfile bundle exec rake test:integration
20
+ # $ BUNDLE_GEMFILE=./gemfiles/7.0.gemfile bundle install
21
+ # $ BUNDLE_GEMFILE=./gemfiles/7.0.gemfile bundle exec rake test:integration
22
22
 
23
23
  source 'https://rubygems.org'
24
24
 
25
25
  gemspec path: '../'
26
26
 
27
- gem 'activemodel', '>= 3.0'
28
- gem 'activerecord', '~> 3.2'
29
- gem 'mongoid', '>= 3.0'
30
- gem 'sqlite3', '> 1.3', '< 1.4' unless defined?(JRUBY_VERSION)
27
+ gem 'activemodel', '~> 7.1'
28
+ gem 'activerecord', '~> 7.1'
29
+ gem 'sqlite3' unless defined?(JRUBY_VERSION)
30
+ # gem 'mongoid', '~> 6'
31
31
 
32
32
  group :development, :testing do
33
- gem 'rspec'
33
+ gem 'debug'
34
34
  gem 'pry-nav'
35
- end
35
+ gem 'rspec'
36
+ end
@@ -17,7 +17,6 @@
17
17
 
18
18
  module Elasticsearch
19
19
  module Model
20
-
21
20
  # Contains an adapter which provides OxM-specific implementations for common behaviour:
22
21
  #
23
22
  # * {Adapter::Adapter#records_mixin Fetching records from the database}
@@ -29,7 +28,6 @@ module Elasticsearch
29
28
  # @see Elasticsearch::Model::Adapter::Mongoid
30
29
  #
31
30
  module Adapter
32
-
33
31
  # Returns an adapter based on the Ruby class passed
34
32
  #
35
33
  # @example Create an adapter for an ActiveRecord-based model
@@ -18,11 +18,9 @@
18
18
  module Elasticsearch
19
19
  module Model
20
20
  module Adapter
21
-
22
21
  # An adapter for ActiveRecord-based models
23
22
  #
24
23
  module ActiveRecord
25
-
26
24
  Adapter.register self,
27
25
  lambda { |klass| !!defined?(::ActiveRecord::Base) && klass.respond_to?(:ancestors) && klass.ancestors.include?(::ActiveRecord::Base) }
28
26
 
@@ -71,7 +69,6 @@ module Elasticsearch
71
69
  end
72
70
 
73
71
  module Callbacks
74
-
75
72
  # Handle index updates (creating, updating or deleting documents)
76
73
  # when the model changes, by hooking into the lifecycle
77
74
  #
@@ -87,7 +84,6 @@ module Elasticsearch
87
84
  end
88
85
 
89
86
  module Importing
90
-
91
87
  # Fetch batches of records from the database (used by the import method)
92
88
  #
93
89
  #
@@ -18,15 +18,12 @@
18
18
  module Elasticsearch
19
19
  module Model
20
20
  module Adapter
21
-
22
21
  # The default adapter for models which haven't one registered
23
22
  #
24
23
  module Default
25
-
26
24
  # Module for implementing methods and logic related to fetching records from the database
27
25
  #
28
26
  module Records
29
-
30
27
  # Return the collection of records fetched from the database
31
28
  #
32
29
  # By default uses `MyModel#find[1, 2, 3]`
@@ -60,7 +57,6 @@ module Elasticsearch
60
57
  raise NotImplemented, "Method not implemented for default adapter"
61
58
  end
62
59
  end
63
-
64
60
  end
65
61
  end
66
62
  end
@@ -18,18 +18,21 @@
18
18
  module Elasticsearch
19
19
  module Model
20
20
  module Adapter
21
-
22
21
  # An adapter for Mongoid-based models
23
22
  #
24
23
  # @see http://mongoid.org
25
24
  #
26
25
  module Mongoid
27
-
28
- Adapter.register self,
29
- lambda { |klass| !!defined?(::Mongoid::Document) && klass.respond_to?(:ancestors) && klass.ancestors.include?(::Mongoid::Document) }
26
+ Adapter.register(
27
+ self,
28
+ lambda do |klass|
29
+ !!defined?(::Mongoid::Document) &&
30
+ klass.respond_to?(:ancestors) &&
31
+ klass.ancestors.include?(::Mongoid::Document)
32
+ end
33
+ )
30
34
 
31
35
  module Records
32
-
33
36
  # Return a `Mongoid::Criteria` instance
34
37
  #
35
38
  def records
@@ -59,7 +62,6 @@ module Elasticsearch
59
62
  end
60
63
 
61
64
  module Callbacks
62
-
63
65
  # Handle index updates (creating, updating or deleting documents)
64
66
  # when the model changes, by hooking into the lifecycle
65
67
  #
@@ -73,7 +75,6 @@ module Elasticsearch
73
75
  end
74
76
 
75
77
  module Importing
76
-
77
78
  # Fetch batches of records from the database
78
79
  #
79
80
  # @see https://github.com/mongoid/mongoid/issues/1334
@@ -88,19 +89,16 @@ module Elasticsearch
88
89
  scope = all
89
90
  scope = scope.send(named_scope) if named_scope
90
91
  scope = query.is_a?(Proc) ? scope.class_exec(&query) : scope.where(query) if query
91
-
92
92
  scope.no_timeout.each_slice(batch_size) do |items|
93
93
  yield (preprocess ? self.__send__(preprocess, items) : items)
94
94
  end
95
95
  end
96
96
 
97
97
  def __transform
98
- lambda {|a| { index: { _id: a.id.to_s, data: a.as_indexed_json } }}
98
+ lambda { |a| { index: { _id: a.id.to_s, data: a.as_indexed_json } } }
99
99
  end
100
100
  end
101
-
102
101
  end
103
-
104
102
  end
105
103
  end
106
104
  end
@@ -18,7 +18,6 @@
18
18
  module Elasticsearch
19
19
  module Model
20
20
  module Adapter
21
-
22
21
  # An adapter to be used for deserializing results from multiple models,
23
22
  # retrieved through `Elasticsearch::Model.search`
24
23
  #
@@ -17,14 +17,12 @@
17
17
 
18
18
  module Elasticsearch
19
19
  module Model
20
-
21
20
  # Provides support for easily and efficiently importing large amounts of
22
21
  # records from the including class into the index.
23
22
  #
24
23
  # @see ClassMethods#import
25
24
  #
26
25
  module Importing
27
-
28
26
  # When included in a model, adds the importing methods.
29
27
  #
30
28
  # @example Import all records from the `Article` model
@@ -42,13 +40,12 @@ module Elasticsearch
42
40
  end
43
41
 
44
42
  module ClassMethods
45
-
46
43
  # Import all model records into the index
47
44
  #
48
45
  # The method will pick up correct strategy based on the `Importing` module
49
46
  # defined in the corresponding adapter.
50
47
  #
51
- # @param options [Hash] Options passed to the underlying `__find_in_batches`method
48
+ # @param options [Hash] Options passed to the underlying `__find_in_batches` method
52
49
  # @param block [Proc] Optional block to evaluate for each batch
53
50
  #
54
51
  # @yield [Hash] Gives the Hash with the Elasticsearch response to the block
@@ -62,7 +59,6 @@ module Elasticsearch
62
59
  # "index" => {
63
60
  # "error" => 'FAILED',
64
61
  # "_index" => "test",
65
- # "_type" => "_doc",
66
62
  # "_id" => '1',
67
63
  # "_version" => 1,
68
64
  # "result" => "foo",
@@ -141,7 +137,6 @@ module Elasticsearch
141
137
  errors = []
142
138
  refresh = options.delete(:refresh) || false
143
139
  target_index = options.delete(:index) || index_name
144
- target_type = options.delete(:type) || document_type
145
140
  transform = options.delete(:transform) || __transform
146
141
  pipeline = options.delete(:pipeline)
147
142
  return_value = options.delete(:return) || 'count'
@@ -161,14 +156,10 @@ module Elasticsearch
161
156
  __find_in_batches(options) do |batch|
162
157
  params = {
163
158
  index: target_index,
164
- type: target_type,
165
159
  body: __batch_to_bulk(batch, transform)
166
160
  }
167
-
168
161
  params[:pipeline] = pipeline if pipeline
169
-
170
162
  response = client.bulk params
171
-
172
163
  yield response if block_given?
173
164
 
174
165
  errors += response['items'].select { |k, v| k.values.first['error'] }
@@ -188,8 +179,6 @@ module Elasticsearch
188
179
  batch.map { |model| transform.call(model) }
189
180
  end
190
181
  end
191
-
192
182
  end
193
-
194
183
  end
195
184
  end
@@ -17,7 +17,6 @@
17
17
 
18
18
  module Elasticsearch
19
19
  module Model
20
-
21
20
  # Provides the necessary support to set up index options (mappings, settings)
22
21
  # as well as instance methods to create, update or delete documents in the index.
23
22
  #
@@ -29,7 +28,6 @@ module Elasticsearch
29
28
  # @see InstanceMethods#delete_document
30
29
  #
31
30
  module Indexing
32
-
33
31
  # Wraps the [index settings](https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html)
34
32
  #
35
33
  class Settings
@@ -51,13 +49,11 @@ module Elasticsearch
51
49
  # Wraps the [index mappings](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html)
52
50
  #
53
51
  class Mappings
54
- attr_accessor :options, :type
52
+ attr_accessor :options
55
53
 
56
- # @private
57
54
  TYPES_WITH_EMBEDDED_PROPERTIES = %w(object nested)
58
55
 
59
- def initialize(type = nil, options={})
60
- @type = type
56
+ def initialize(options={})
61
57
  @options = options
62
58
  @mapping = {}
63
59
  end
@@ -87,11 +83,7 @@ module Elasticsearch
87
83
  end
88
84
 
89
85
  def to_hash
90
- if @type
91
- { @type.to_sym => @options.merge( properties: @mapping ) }
92
- else
93
- @options.merge( properties: @mapping )
94
- end
86
+ @options.merge( properties: @mapping )
95
87
  end
96
88
 
97
89
  def as_json(options={})
@@ -100,7 +92,6 @@ module Elasticsearch
100
92
  end
101
93
 
102
94
  module ClassMethods
103
-
104
95
  # Defines mappings for the index
105
96
  #
106
97
  # @example Define mapping for model
@@ -152,7 +143,7 @@ module Elasticsearch
152
143
  # when it doesn't already define them. Use the `__elasticsearch__` proxy otherwise.
153
144
  #
154
145
  def mapping(options={}, &block)
155
- @mapping ||= Mappings.new(document_type, options)
146
+ @mapping ||= Mappings.new(options)
156
147
 
157
148
  @mapping.options.update(options) unless options.empty?
158
149
 
@@ -290,7 +281,7 @@ module Elasticsearch
290
281
  self.client.indices.delete index: target_index
291
282
  rescue Exception => e
292
283
  if e.class.to_s =~ /NotFound/ && options[:force]
293
- client.transport.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.transport.logger
284
+ client.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.logger
294
285
  nil
295
286
  else
296
287
  raise e
@@ -317,7 +308,7 @@ module Elasticsearch
317
308
  self.client.indices.refresh index: target_index
318
309
  rescue Exception => e
319
310
  if e.class.to_s =~ /NotFound/ && options[:force]
320
- client.transport.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.transport.logger
311
+ client.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.logger
321
312
  nil
322
313
  else
323
314
  raise e
@@ -372,7 +363,6 @@ module Elasticsearch
372
363
  request = { index: index_name,
373
364
  id: id,
374
365
  body: document }
375
- request.merge!(type: document_type) if document_type
376
366
 
377
367
  client.index(request.merge!(options))
378
368
  end
@@ -393,7 +383,6 @@ module Elasticsearch
393
383
  def delete_document(options={})
394
384
  request = { index: index_name,
395
385
  id: self.id }
396
- request.merge!(type: document_type) if document_type
397
386
 
398
387
  client.delete(request.merge!(options))
399
388
  end
@@ -434,7 +423,6 @@ module Elasticsearch
434
423
  request = { index: index_name,
435
424
  id: self.id,
436
425
  body: { doc: attributes } }
437
- request.merge!(type: document_type) if document_type
438
426
 
439
427
  client.update(request.merge!(options))
440
428
  end
@@ -461,7 +449,6 @@ module Elasticsearch
461
449
  request = { index: index_name,
462
450
  id: self.id,
463
451
  body: { doc: attributes } }
464
- request.merge!(type: document_type) if document_type
465
452
 
466
453
  client.update(request.merge!(options))
467
454
  end
@@ -17,7 +17,6 @@
17
17
 
18
18
  module Elasticsearch
19
19
  module Model
20
-
21
20
  # Keeps a global registry of classes that include `Elasticsearch::Model`
22
21
  #
23
22
  class Registry
@@ -80,17 +79,9 @@ module Elasticsearch
80
79
  models.map { |m| m.index_name }
81
80
  end
82
81
 
83
- # Get an Array of document types used for retrieving documents when doing a search across multiple models
84
- #
85
- # @return [Array] the list of document types used for retrieving documents
86
- #
87
- def document_type
88
- models.map { |m| m.document_type }.compact.presence
89
- end
90
-
91
82
  # Get the client common for all models
92
83
  #
93
- # @return Elasticsearch::Transport::Client
84
+ # @return Elastic::Transport::Client
94
85
  #
95
86
  def client
96
87
  Elasticsearch::Model.client