diff --git a/.github/workflows/2.7.yml b/.github/workflows/2.7.yml index 8bfd9b66f..69741988a 100644 --- a/.github/workflows/2.7.yml +++ b/.github/workflows/2.7.yml @@ -13,7 +13,7 @@ jobs: tests: env: TEST_ES_SERVER: http://localhost:9200 - RAILS_VERSIONS: '5.0,6.0' + RAILS_VERSIONS: '6.0,7.0' strategy: fail-fast: false runs-on: ubuntu-latest @@ -27,7 +27,9 @@ jobs: sudo sysctl -w vm.max_map_count=262144 - uses: elastic/elastic-github-actions/elasticsearch@master with: - stack-version: 7.x-SNAPSHOT + stack-version: 8.8.0-SNAPSHOT + security-enabled: false + action.destructive_requires_name: false - uses: ruby/setup-ruby@v1 with: ruby-version: 2.7 diff --git a/.github/workflows/2.6.yml b/.github/workflows/3.2.2.yml similarity index 85% rename from .github/workflows/2.6.yml rename to .github/workflows/3.2.2.yml index c003a58e5..7b2114638 100644 --- a/.github/workflows/2.6.yml +++ b/.github/workflows/3.2.2.yml @@ -1,4 +1,4 @@ -name: Ruby 2.6 +name: Ruby 3.2.2 on: push: branches: @@ -13,7 +13,7 @@ jobs: tests: env: TEST_ES_SERVER: http://localhost:9200 - RAILS_VERSIONS: '5.0,6.0' + RAILS_VERSIONS: '6.0,7.0' strategy: fail-fast: false runs-on: ubuntu-latest @@ -27,10 +27,12 @@ jobs: sudo sysctl -w vm.max_map_count=262144 - uses: elastic/elastic-github-actions/elasticsearch@master with: - stack-version: 7.x-SNAPSHOT + stack-version: 8.8.0-SNAPSHOT + security-enabled: false + action.destructive_requires_name: false - uses: ruby/setup-ruby@v1 with: - ruby-version: 2.6 + ruby-version: 3.2.2 - name: Bundle run: | sudo apt-get install libsqlite3-dev diff --git a/.github/workflows/jruby.yml b/.github/workflows/jruby.yml index 7a3ec1be7..2615d0569 100644 --- a/.github/workflows/jruby.yml +++ b/.github/workflows/jruby.yml @@ -13,7 +13,7 @@ jobs: tests: env: TEST_ES_SERVER: http://localhost:9200 - RAILS_VERSIONS: '5.0,6.0' + RAILS_VERSIONS: '6.0,7.0' strategy: fail-fast: false runs-on: ubuntu-latest @@ -27,10 +27,11 @@ jobs: sudo sysctl -w vm.max_map_count=262144 - uses: elastic/elastic-github-actions/elasticsearch@master with: - stack-version: 7.x-SNAPSHOT + stack-version: 8.8.0-SNAPSHOT + security-enabled: false - uses: ruby/setup-ruby@v1 with: - ruby-version: jruby-9.3 + ruby-version: jruby-9.4.2.0 - name: Bundle run: | sudo apt-get install libsqlite3-dev diff --git a/Gemfile b/Gemfile index 0edd2dd95..23993bd9d 100644 --- a/Gemfile +++ b/Gemfile @@ -19,7 +19,7 @@ source 'https://rubygems.org' gem 'ansi' gem 'cane' -gem 'elasticsearch', '~> 7' +gem 'elasticsearch', '~> 8.7.0' gem 'pry' gem 'rake', '~> 12' diff --git a/README.md b/README.md index 26ee3860e..ce45efb45 100644 --- a/README.md +++ b/README.md @@ -162,6 +162,14 @@ You can also unit, integration, or both tests for all sub-projects from the top- The test suite expects an Elasticsearch cluster running on port 9250, and **will delete all the data**. +``` +docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "xpack.security.enabled=false" -e "action.destructive_requires_name=false" elasticsearch:8.7.0 +``` + +``` +docker run --name mongodb -d mongo:5 +``` + ## License This software is licensed under the Apache 2 license, quoted below. diff --git a/Rakefile b/Rakefile index 9b3347f86..4d49a8f34 100644 --- a/Rakefile +++ b/Rakefile @@ -163,7 +163,7 @@ task :wait_for_green do ready = true break end - rescue Elasticsearch::Transport::Transport::Errors::RequestTimeout => ex + rescue Elastic::Transport::Transport::Errors::RequestTimeout => ex puts "Couldn't confirm green status.\n#{ex.inspect}." rescue Faraday::ConnectionFailed => ex puts "Couldn't connect to Elasticsearch.\n#{ex.inspect}." diff --git a/elasticsearch-model/README.md b/elasticsearch-model/README.md index c7d90150a..e4675d0e4 100644 --- a/elasticsearch-model/README.md +++ b/elasticsearch-model/README.md @@ -413,13 +413,12 @@ Article.__elasticsearch__.create_index! force: true Article.__elasticsearch__.refresh_index! ``` -By default, index name and document type will be inferred from your class name, +By default, index name will be inferred from your class name, you can set it explicitly, however: ```ruby class Article index_name "articles-#{Rails.env}" - document_type "post" end ``` @@ -531,7 +530,7 @@ class Indexer when /delete/ begin Client.delete index: 'articles', type: 'article', id: record_id - rescue Elasticsearch::Transport::Transport::Errors::NotFound + rescue Elastic::Transport::Transport::Errors::NotFound logger.debug "Article not found, ID: #{record_id}" end else raise ArgumentError, "Unknown operation '#{operation}'" @@ -762,9 +761,9 @@ This software is licensed under the Apache 2 license, quoted below. the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - + http://www.apache.org/licenses/LICENSE-2.0 - + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY diff --git a/elasticsearch-model/Rakefile b/elasticsearch-model/Rakefile index 6e03532b0..74c155500 100644 --- a/elasticsearch-model/Rakefile +++ b/elasticsearch-model/Rakefile @@ -21,7 +21,7 @@ desc 'Run unit tests' task default: 'test:all' task test: 'test:all' -gemfiles = ['5.0.gemfile', '6.0.gemfile'] +gemfiles = ['5.0.gemfile', '6.0.gemfile', '7.0.gemfile'] gemfiles << '4.0.gemfile' if RUBY_VERSION < '2.7' GEMFILES = gemfiles.freeze diff --git a/elasticsearch-model/elasticsearch-model.gemspec b/elasticsearch-model/elasticsearch-model.gemspec index b8f16c902..1ec7a32f3 100644 --- a/elasticsearch-model/elasticsearch-model.gemspec +++ b/elasticsearch-model/elasticsearch-model.gemspec @@ -42,7 +42,7 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.4' s.add_dependency 'activesupport', '> 3' - s.add_dependency 'elasticsearch', '~> 7' + s.add_dependency 'elasticsearch', '~> 8.7.0' s.add_dependency 'hashie' s.add_development_dependency 'activemodel', '> 3' diff --git a/elasticsearch-model/gemfiles/7.0.gemfile b/elasticsearch-model/gemfiles/7.0.gemfile new file mode 100644 index 000000000..4cf9f4f8f --- /dev/null +++ b/elasticsearch-model/gemfiles/7.0.gemfile @@ -0,0 +1,35 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Usage: +# +# $ BUNDLE_GEMFILE=./gemfiles/6.0.gemfile bundle install +# $ BUNDLE_GEMFILE=./gemfiles/6.0.gemfile bundle exec rake test:integration + +source 'https://rubygems.org' + +gemspec path: '../' + +gem 'activemodel', '~> 7.0' +gem 'activerecord', '~> 7.0' +gem 'sqlite3' unless defined?(JRUBY_VERSION) +# gem 'mongoid', '~> 6' + +group :development, :testing do + gem 'pry-nav' + gem 'rspec' +end diff --git a/elasticsearch-model/lib/elasticsearch/model.rb b/elasticsearch-model/lib/elasticsearch/model.rb index af2f34cb6..7efc5caa9 100644 --- a/elasticsearch-model/lib/elasticsearch/model.rb +++ b/elasticsearch-model/lib/elasticsearch/model.rb @@ -85,7 +85,7 @@ module Elasticsearch # # ... # module Model - METHODS = [:search, :mapping, :mappings, :settings, :index_name, :document_type, :import] + METHODS = [:search, :mapping, :mappings, :settings, :index_name, :import] # Adds the `Elasticsearch::Model` functionality to the including class. # diff --git a/elasticsearch-model/lib/elasticsearch/model/importing.rb b/elasticsearch-model/lib/elasticsearch/model/importing.rb index 927dd16ee..9d5f7e756 100644 --- a/elasticsearch-model/lib/elasticsearch/model/importing.rb +++ b/elasticsearch-model/lib/elasticsearch/model/importing.rb @@ -141,7 +141,6 @@ def import(options={}, &block) errors = [] refresh = options.delete(:refresh) || false target_index = options.delete(:index) || index_name - target_type = options.delete(:type) || document_type transform = options.delete(:transform) || __transform pipeline = options.delete(:pipeline) return_value = options.delete(:return) || 'count' @@ -161,7 +160,6 @@ def import(options={}, &block) __find_in_batches(options) do |batch| params = { index: target_index, - type: target_type, body: __batch_to_bulk(batch, transform) } diff --git a/elasticsearch-model/lib/elasticsearch/model/indexing.rb b/elasticsearch-model/lib/elasticsearch/model/indexing.rb index 3ebd8cfb4..eb2c3df06 100644 --- a/elasticsearch-model/lib/elasticsearch/model/indexing.rb +++ b/elasticsearch-model/lib/elasticsearch/model/indexing.rb @@ -51,13 +51,12 @@ def as_json(options={}) # Wraps the [index mappings](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html) # class Mappings - attr_accessor :options, :type + attr_accessor :options # @private TYPES_WITH_EMBEDDED_PROPERTIES = %w(object nested) - def initialize(type = nil, options={}) - @type = type + def initialize(options={}) @options = options @mapping = {} end @@ -152,7 +151,7 @@ module ClassMethods # when it doesn't already define them. Use the `__elasticsearch__` proxy otherwise. # def mapping(options={}, &block) - @mapping ||= Mappings.new(document_type, options) + @mapping ||= Mappings.new(options) @mapping.options.update(options) unless options.empty? @@ -290,7 +289,7 @@ def delete_index!(options={}) self.client.indices.delete index: target_index rescue Exception => e if e.class.to_s =~ /NotFound/ && options[:force] - client.transport.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.transport.logger + client.transport.logger.debug("[!!!] Index does not exist (#{e.class})") if client.transport.logger nil else raise e @@ -372,7 +371,6 @@ def index_document(options={}) request = { index: index_name, id: id, body: document } - request.merge!(type: document_type) if document_type client.index(request.merge!(options)) end @@ -393,7 +391,6 @@ def index_document(options={}) def delete_document(options={}) request = { index: index_name, id: self.id } - request.merge!(type: document_type) if document_type client.delete(request.merge!(options)) end @@ -434,7 +431,6 @@ def update_document(options={}) request = { index: index_name, id: self.id, body: { doc: attributes } } - request.merge!(type: document_type) if document_type client.update(request.merge!(options)) end @@ -461,7 +457,6 @@ def update_document_attributes(attributes, options={}) request = { index: index_name, id: self.id, body: { doc: attributes } } - request.merge!(type: document_type) if document_type client.update(request.merge!(options)) end diff --git a/elasticsearch-model/lib/elasticsearch/model/multimodel.rb b/elasticsearch-model/lib/elasticsearch/model/multimodel.rb index 6b5fc2a81..059e540d3 100644 --- a/elasticsearch-model/lib/elasticsearch/model/multimodel.rb +++ b/elasticsearch-model/lib/elasticsearch/model/multimodel.rb @@ -80,18 +80,6 @@ def index_name models.map { |m| m.index_name } end - # Get an Array of document types used for retrieving documents when doing a search across multiple models - # - # @return [Array] the list of document types used for retrieving documents - # - def document_type - models.map { |m| m.document_type }.compact.presence - end - - # Get the client common for all models - # - # @return Elasticsearch::Transport::Client - # def client Elasticsearch::Model.client end diff --git a/elasticsearch-model/lib/elasticsearch/model/naming.rb b/elasticsearch-model/lib/elasticsearch/model/naming.rb index c4c796ab2..1cfbc1ff5 100644 --- a/elasticsearch-model/lib/elasticsearch/model/naming.rb +++ b/elasticsearch-model/lib/elasticsearch/model/naming.rb @@ -64,31 +64,6 @@ def index_name=(name) @index_name = name end - # Get or set the document type - # - # @example Set the document type for the `Article` model - # - # class Article - # document_type "my-article" - # end - # - # @example Directly set the document type for the `Article` model - # - # Article.document_type "my-article" - # - def document_type name=nil - @document_type = name || @document_type || implicit(:document_type) - end - - - # Set the document type - # - # @see document_type - # - def document_type=(name) - @document_type = name - end - private def implicit(prop) @@ -98,8 +73,6 @@ def implicit(prop) def default_index_name self.model_name.collection.gsub(/\//, '-') end - - def default_document_type; end end module InstanceMethods @@ -129,25 +102,7 @@ def index_name name=nil, &block def index_name=(name) @index_name = name end - - # @example Set the document type for an instance of the `Article` model - # - # @article.document_type "my-article" - # @article.__elasticsearch__.update_document - # - def document_type name=nil - @document_type = name || @document_type || self.class.document_type - end - - # Set the document type - # - # @see document_type - # - def document_type=(name) - @document_type = name - end end - end end end diff --git a/elasticsearch-model/lib/elasticsearch/model/searching.rb b/elasticsearch-model/lib/elasticsearch/model/searching.rb index 714f98a22..e913444dd 100644 --- a/elasticsearch-model/lib/elasticsearch/model/searching.rb +++ b/elasticsearch-model/lib/elasticsearch/model/searching.rb @@ -37,7 +37,6 @@ def initialize(klass, query_or_payload, options={}) @options = options __index_name = options[:index] || klass.index_name - __document_type = options[:type] || klass.document_type case # search query: ... @@ -54,9 +53,9 @@ def initialize(klass, query_or_payload, options={}) end if body - @definition = { index: __index_name, type: __document_type, body: body }.update options + @definition = { index: __index_name, body: body }.update options else - @definition = { index: __index_name, type: __document_type, q: q }.update options + @definition = { index: __index_name, q: q }.update options end end diff --git a/elasticsearch-model/lib/elasticsearch/model/version.rb b/elasticsearch-model/lib/elasticsearch/model/version.rb index cdd631896..c939ccf4a 100644 --- a/elasticsearch-model/lib/elasticsearch/model/version.rb +++ b/elasticsearch-model/lib/elasticsearch/model/version.rb @@ -17,6 +17,6 @@ module Elasticsearch module Model - VERSION = "7.2.1" + VERSION = "8.7.0" end end diff --git a/elasticsearch-model/spec/elasticsearch/model/adapters/active_record/basic_spec.rb b/elasticsearch-model/spec/elasticsearch/model/adapters/active_record/basic_spec.rb index a769b38f6..dd2509a46 100644 --- a/elasticsearch-model/spec/elasticsearch/model/adapters/active_record/basic_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/adapters/active_record/basic_spec.rb @@ -54,7 +54,7 @@ end end - context 'when a document_type is defined for the Model' do + context 'when a document_type is defined for the Model ?!' do before(:all) do ActiveRecord::Schema.define(:version => 1) do @@ -67,7 +67,7 @@ end Article.delete_all - Article.__elasticsearch__.create_index!(force: true, include_type_name: true) + Article.__elasticsearch__.create_index!(force: true) Article.create!(title: 'Test', body: '', clicks: 1) Article.create!(title: 'Testing Coding', body: '', clicks: 2) diff --git a/elasticsearch-model/spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb b/elasticsearch-model/spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb index 730dad0e0..09f4670a6 100644 --- a/elasticsearch-model/spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb @@ -27,7 +27,7 @@ end MyNamespace::Book.delete_all - MyNamespace::Book.__elasticsearch__.create_index!(force: true, include_type_name: true) + MyNamespace::Book.__elasticsearch__.create_index!(force: true) MyNamespace::Book.create!(title: 'Test') MyNamespace::Book.__elasticsearch__.refresh_index! end @@ -43,10 +43,6 @@ expect(MyNamespace::Book.index_name).to eq('my_namespace-books') end - it 'has the proper document type' do - expect(MyNamespace::Book.document_type).to eq('book') - end - it 'saves the document into the index' do expect(MyNamespace::Book.search('title:test').results.size).to eq(1) expect(MyNamespace::Book.search('title:test').results.first.title).to eq('Test') diff --git a/elasticsearch-model/spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb b/elasticsearch-model/spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb index 5147943ee..06790f613 100644 --- a/elasticsearch-model/spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb @@ -38,7 +38,7 @@ add_index(:answers, :question_id) unless index_exists?(:answers, :question_id) clear_tables(Question) - ParentChildSearchable.create_index!(force: true, include_type_name: true) + ParentChildSearchable.create_index!(force: true) q_1 = Question.create!(title: 'First Question', author: 'John') q_2 = Question.create!(title: 'Second Question', author: 'Jody') diff --git a/elasticsearch-model/spec/elasticsearch/model/adapters/multiple_spec.rb b/elasticsearch-model/spec/elasticsearch/model/adapters/multiple_spec.rb index eb5a983b0..c79e98700 100644 --- a/elasticsearch-model/spec/elasticsearch/model/adapters/multiple_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/adapters/multiple_spec.rb @@ -24,7 +24,6 @@ class DummyOne include Elasticsearch::Model index_name 'dummy' - document_type 'dummy_one' def self.find(ids) ids.map { |id| new(id) } @@ -42,7 +41,6 @@ class DummyTwo include Elasticsearch::Model index_name 'dummy' - document_type 'dummy_two' def self.find(ids) ids.map { |id| new(id) } @@ -60,7 +58,6 @@ class DummyTwo include Elasticsearch::Model index_name 'other_index' - document_type 'dummy_two' def self.find(ids) ids.map { |id| new(id) } @@ -86,27 +83,22 @@ def initialize(id) [ { _index: 'dummy', - _type: 'dummy_two', _id: '2' }, { _index: 'dummy', - _type: 'dummy_one', _id: '2' }, { _index: 'other_index', - _type: 'dummy_two', _id: '1' }, { _index: 'dummy', - _type: 'dummy_two', _id: '1' }, { _index: 'dummy', - _type: 'dummy_one', _id: '3' } ] diff --git a/elasticsearch-model/spec/elasticsearch/model/importing_spec.rb b/elasticsearch-model/spec/elasticsearch/model/importing_spec.rb index 02cde6d6c..9a668b37f 100644 --- a/elasticsearch-model/spec/elasticsearch/model/importing_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/importing_spec.rb @@ -60,7 +60,6 @@ def importing_mixin before do allow(DummyImportingModel).to receive(:index_name).and_return('foo') - allow(DummyImportingModel).to receive(:document_type).and_return('foo') allow(DummyImportingModel).to receive(:index_exists?).and_return(true) allow(DummyImportingModel).to receive(:__batch_to_bulk) allow(client).to receive(:bulk).and_return(response) @@ -159,7 +158,7 @@ def importing_mixin before do expect(DummyImportingModel).to receive(:client).and_return(client) - expect(client).to receive(:bulk).with(body: nil, index: 'my-new-index', type: 'foo').and_return(response) + expect(client).to receive(:bulk).with(body: nil, index: 'my-new-index').and_return(response) end it 'uses the alternate index name' do @@ -171,11 +170,11 @@ def importing_mixin before do expect(DummyImportingModel).to receive(:client).and_return(client) - expect(client).to receive(:bulk).with(body: nil, index: 'foo', type: 'my-new-type').and_return(response) + expect(client).to receive(:bulk).with(body: nil, index: 'foo').and_return(response) end it 'uses the alternate index name' do - expect(DummyImportingModel.import(type: 'my-new-type')).to eq(0) + expect(DummyImportingModel.import()).to eq(0) end end @@ -232,7 +231,7 @@ def importing_mixin before do expect(DummyImportingModel).to receive(:client).and_return(client) - expect(client).to receive(:bulk).with(body: nil, index: 'foo', type: 'foo', pipeline: 'my-pipeline').and_return(response) + expect(client).to receive(:bulk).with(body: nil, index: 'foo', pipeline: 'my-pipeline').and_return(response) end it 'uses the pipeline option' do diff --git a/elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb b/elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb index eb9651a73..33abdf8cb 100644 --- a/elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb @@ -94,7 +94,7 @@ class NotFound < Exception; end describe '#mappings' do let(:expected_mapping_hash) do - { :mytype => { foo: 'bar', :properties => {} } } + { foo: 'bar', :properties => {} } end it 'returns an instance of the Mappings class' do @@ -106,17 +106,17 @@ class NotFound < Exception; end end it 'should be convertible to a hash' do - expect(Elasticsearch::Model::Indexing::Mappings.new(:mytype, { foo: 'bar' }).to_hash).to eq(expected_mapping_hash) + expect(Elasticsearch::Model::Indexing::Mappings.new({ foo: 'bar' }).to_hash).to eq(expected_mapping_hash) end it 'should be convertible to json' do - expect(Elasticsearch::Model::Indexing::Mappings.new(:mytype, { foo: 'bar' }).as_json).to eq(expected_mapping_hash) + expect(Elasticsearch::Model::Indexing::Mappings.new({ foo: 'bar' }).as_json).to eq(expected_mapping_hash) end context 'when a type is specified' do let(:mappings) do - Elasticsearch::Model::Indexing::Mappings.new(:mytype) + Elasticsearch::Model::Indexing::Mappings.new() end before do @@ -125,30 +125,11 @@ class NotFound < Exception; end end it 'creates the correct mapping definition' do - expect(mappings.to_hash[:mytype][:properties][:foo][:type]).to eq('boolean') + expect(mappings.to_hash[:properties][:foo][:type]).to eq('boolean') end it 'uses text as the default field type' do - expect(mappings.to_hash[:mytype][:properties][:bar][:type]).to eq('text') - end - - context 'when the \'include_type_name\' option is specified' do - - let(:mappings) do - Elasticsearch::Model::Indexing::Mappings.new(:mytype, include_type_name: true) - end - - before do - mappings.indexes :foo, { type: 'boolean', include_in_all: false } - end - - it 'creates the correct mapping definition' do - expect(mappings.to_hash[:mytype][:properties][:foo][:type]).to eq('boolean') - end - - it 'sets the \'include_type_name\' option' do - expect(mappings.to_hash[:mytype][:include_type_name]).to eq(true) - end + expect(mappings.to_hash[:properties][:bar][:type]).to eq('text') end end @@ -172,10 +153,10 @@ class NotFound < Exception; end end end - context 'when specific mappings are defined' do + context 'when specific mappings are defined ?!' do let(:mappings) do - Elasticsearch::Model::Indexing::Mappings.new(:mytype, include_type_name: true) + Elasticsearch::Model::Indexing::Mappings.new() end before do @@ -184,11 +165,11 @@ class NotFound < Exception; end end it 'creates the correct mapping definition' do - expect(mappings.to_hash[:mytype][:properties][:foo][:type]).to eq('boolean') + expect(mappings.to_hash[:properties][:foo][:type]).to eq('boolean') end it 'uses text as the default type' do - expect(mappings.to_hash[:mytype][:properties][:bar][:type]).to eq('text') + expect(mappings.to_hash[:properties][:bar][:type]).to eq('text') end context 'when mappings are defined for multiple fields' do @@ -200,9 +181,9 @@ class NotFound < Exception; end end it 'defines the mapping for all the fields' do - expect(mappings.to_hash[:mytype][:properties][:my_field][:type]).to eq('text') - expect(mappings.to_hash[:mytype][:properties][:my_field][:fields][:raw][:type]).to eq('keyword') - expect(mappings.to_hash[:mytype][:properties][:my_field][:fields][:raw][:properties]).to be_nil + expect(mappings.to_hash[:properties][:my_field][:type]).to eq('text') + expect(mappings.to_hash[:properties][:my_field][:fields][:raw][:type]).to eq('keyword') + expect(mappings.to_hash[:properties][:my_field][:fields][:raw][:properties]).to be_nil end end @@ -227,25 +208,21 @@ class NotFound < Exception; end end it 'defines mappings for the embedded properties' do - expect(mappings.to_hash[:mytype][:properties][:foo][:type]).to eq('object') - expect(mappings.to_hash[:mytype][:properties][:foo][:properties][:bar][:type]).to eq('text') - expect(mappings.to_hash[:mytype][:properties][:foo][:fields]).to be_nil + expect(mappings.to_hash[:properties][:foo][:type]).to eq('object') + expect(mappings.to_hash[:properties][:foo][:properties][:bar][:type]).to eq('text') + expect(mappings.to_hash[:properties][:foo][:fields]).to be_nil - expect(mappings.to_hash[:mytype][:properties][:foo_object][:type]).to eq('object') - expect(mappings.to_hash[:mytype][:properties][:foo_object][:properties][:bar][:type]).to eq('text') - expect(mappings.to_hash[:mytype][:properties][:foo_object][:fields]).to be_nil + expect(mappings.to_hash[:properties][:foo_object][:type]).to eq('object') + expect(mappings.to_hash[:properties][:foo_object][:properties][:bar][:type]).to eq('text') + expect(mappings.to_hash[:properties][:foo_object][:fields]).to be_nil - expect(mappings.to_hash[:mytype][:properties][:foo_nested][:type]).to eq('nested') - expect(mappings.to_hash[:mytype][:properties][:foo_nested][:properties][:bar][:type]).to eq('text') - expect(mappings.to_hash[:mytype][:properties][:foo_nested][:fields]).to be_nil - - expect(mappings.to_hash[:mytype][:properties][:foo_nested_as_symbol][:type]).to eq(:nested) - expect(mappings.to_hash[:mytype][:properties][:foo_nested_as_symbol][:properties]).not_to be_nil - expect(mappings.to_hash[:mytype][:properties][:foo_nested_as_symbol][:fields]).to be_nil - end + expect(mappings.to_hash[:properties][:foo_nested][:type]).to eq('nested') + expect(mappings.to_hash[:properties][:foo_nested][:properties][:bar][:type]).to eq('text') + expect(mappings.to_hash[:properties][:foo_nested][:fields]).to be_nil - it 'defines the settings' do - expect(mappings.to_hash[:mytype][:include_type_name]).to be(true) + expect(mappings.to_hash[:properties][:foo_nested_as_symbol][:type]).to eq(:nested) + expect(mappings.to_hash[:properties][:foo_nested_as_symbol][:properties]).not_to be_nil + expect(mappings.to_hash[:properties][:foo_nested_as_symbol][:fields]).to be_nil end end end @@ -282,13 +259,12 @@ class NotFound < Exception; end before do DummyIndexingModel.instance_variable_set(:@mapping, nil) - DummyIndexingModel.document_type(:mytype) DummyIndexingModel.mappings(foo: 'boo') DummyIndexingModel.mappings(bar: 'bam') end let(:expected_mappings_hash) do - { mytype: { foo: "boo", bar: "bam", properties: {} } } + { foo: "boo", bar: "bam", properties: {} } end it 'sets the mappings' do @@ -418,7 +394,6 @@ def changes expect(instance).to receive(:client).and_return(client) expect(instance).to receive(:as_indexed_json).and_return('JSON') expect(instance).to receive(:index_name).and_return('foo') - expect(instance).to receive(:document_type).twice.and_return('bar') expect(instance).to receive(:id).and_return('1') end @@ -433,7 +408,7 @@ def changes context 'when no options are passed to the method' do before do - expect(client).to receive(:index).with(index: 'foo', type: 'bar', id: '1', body: 'JSON').and_return(true) + expect(client).to receive(:index).with(index: 'foo', id: '1', body: 'JSON').and_return(true) end it 'provides the method on an instance' do @@ -444,7 +419,7 @@ def changes context 'when extra options are passed to the method' do before do - expect(client).to receive(:index).with(index: 'foo', type: 'bar', id: '1', body: 'JSON', parent: 'A').and_return(true) + expect(client).to receive(:index).with(index: 'foo', id: '1', body: 'JSON', parent: 'A').and_return(true) end it 'passes the extra options to the method call on the client' do @@ -458,7 +433,6 @@ def changes before do expect(instance).to receive(:client).and_return(client) expect(instance).to receive(:index_name).and_return('foo') - expect(instance).to receive(:document_type).twice.and_return('bar') expect(instance).to receive(:id).and_return('1') end @@ -473,7 +447,7 @@ def changes context 'when no options are passed to the method' do before do - expect(client).to receive(:delete).with(index: 'foo', type: 'bar', id: '1').and_return(true) + expect(client).to receive(:delete).with(index: 'foo', id: '1').and_return(true) end it 'provides the method on an instance' do @@ -484,7 +458,7 @@ def changes context 'when extra options are passed to the method' do before do - expect(client).to receive(:delete).with(index: 'foo', type: 'bar', id: '1', parent: 'A').and_return(true) + expect(client).to receive(:delete).with(index: 'foo', id: '1', parent: 'A').and_return(true) end it 'passes the extra options to the method call on the client' do @@ -521,7 +495,6 @@ def changes before do allow(instance).to receive(:client).and_return(client) allow(instance).to receive(:index_name).and_return('foo') - allow(instance).to receive(:document_type).and_return('bar') allow(instance).to receive(:id).and_return('1') end @@ -529,7 +502,7 @@ def changes before do instance.instance_variable_set(:@__changed_model_attributes, { foo: 'bar' }) - expect(client).to receive(:update).with(index: 'foo', type: 'bar', id: '1', body: { doc: { foo: 'bar' } }).and_return(true) + expect(client).to receive(:update).with(index: 'foo', id: '1', body: { doc: { foo: 'bar' } }).and_return(true) end it 'updates the document' do @@ -545,7 +518,7 @@ def changes before do instance.instance_variable_set(:@__changed_model_attributes, {'foo' => 'B', 'bar' => 'D' }) - expect(client).to receive(:update).with(index: 'foo', type: 'bar', id: '1', body: { doc: { foo: 'B' } }).and_return(true) + expect(client).to receive(:update).with(index: 'foo', id: '1', body: { doc: { foo: 'B' } }).and_return(true) end it 'updates the document' do @@ -577,7 +550,7 @@ def changes before do instance.instance_variable_set(:@__changed_model_attributes, { 'foo' => { 'bar' => 'BAR'} }) expect(instance).to receive(:as_indexed_json).and_return('foo' => 'BAR') - expect(client).to receive(:update).with(index: 'foo', type: 'bar', id: '1', body: { doc: { 'foo' => 'BAR' } }).and_return(true) + expect(client).to receive(:update).with(index: 'foo', id: '1', body: { doc: { 'foo' => 'BAR' } }).and_return(true) end it 'updates the document' do @@ -602,7 +575,6 @@ def changes before do expect(instance).to receive(:client).and_return(client) expect(instance).to receive(:index_name).and_return('foo') - expect(instance).to receive(:document_type).twice.and_return('bar') expect(instance).to receive(:id).and_return('1') instance.instance_variable_set(:@__changed_model_attributes, { author: 'john' }) end @@ -610,7 +582,7 @@ def changes context 'when no options are specified' do before do - expect(client).to receive(:update).with(index: 'foo', type: 'bar', id: '1', body: { doc: { title: 'green' } }).and_return(true) + expect(client).to receive(:update).with(index: 'foo', id: '1', body: { doc: { title: 'green' } }).and_return(true) end it 'updates the document' do @@ -621,7 +593,7 @@ def changes context 'when extra options are provided' do before do - expect(client).to receive(:update).with(index: 'foo', type: 'bar', id: '1', body: { doc: { title: 'green' } }, refresh: true).and_return(true) + expect(client).to receive(:update).with(index: 'foo', id: '1', body: { doc: { title: 'green' } }, refresh: true).and_return(true) end it 'updates the document' do @@ -678,7 +650,7 @@ class ::DummyIndexingModelForRecreate context 'when the index is not found' do let(:logger) { nil } let(:transport) do - Elasticsearch::Transport::Client.new(logger: logger) + Elastic::Transport::Client.new(logger: logger) end let(:client) do @@ -918,7 +890,7 @@ class ::DummyIndexingModelForRefresh end let(:transport) do - Elasticsearch::Transport::Client.new(logger: nil) + Elastic::Transport::Client.new(logger: nil) end let(:indices) do @@ -949,7 +921,7 @@ class ::DummyIndexingModelForRefresh end let(:transport) do - Elasticsearch::Transport::Client.new(logger: logger) + Elastic::Transport::Client.new(logger: logger) end it 'does not raise an exception' do diff --git a/elasticsearch-model/spec/elasticsearch/model/module_spec.rb b/elasticsearch-model/spec/elasticsearch/model/module_spec.rb index ed7a58297..8808475ee 100644 --- a/elasticsearch-model/spec/elasticsearch/model/module_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/module_spec.rb @@ -65,7 +65,6 @@ def self.search(query, options={}) expect(DummyIncludingModel).to respond_to(:mapping) expect(DummyIncludingModel).to respond_to(:settings) expect(DummyIncludingModel).to respond_to(:index_name) - expect(DummyIncludingModel).to respond_to(:document_type) expect(DummyIncludingModel).to respond_to(:import) end diff --git a/elasticsearch-model/spec/elasticsearch/model/multimodel_spec.rb b/elasticsearch-model/spec/elasticsearch/model/multimodel_spec.rb index 3652dac1e..c12a5da6b 100644 --- a/elasticsearch-model/spec/elasticsearch/model/multimodel_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/multimodel_spec.rb @@ -24,21 +24,17 @@ end let(:model_1) do - double('Foo', index_name: 'foo_index', document_type: 'foo', to_ary: nil) + double('Foo', index_name: 'foo_index', to_ary: nil) end let(:model_2) do - double('Bar', index_name: 'bar_index', document_type: 'bar', to_ary: nil) + double('Bar', index_name: 'bar_index', to_ary: nil) end it 'has an index name' do expect(multimodel.index_name).to eq(['foo_index', 'bar_index']) end - it 'has an document type' do - expect(multimodel.document_type).to eq(['foo', 'bar']) - end - it 'has a client' do expect(multimodel.client).to eq(Elasticsearch::Model.client) end diff --git a/elasticsearch-model/spec/elasticsearch/model/naming_spec.rb b/elasticsearch-model/spec/elasticsearch/model/naming_spec.rb index 57a53b8d7..d9aec040f 100644 --- a/elasticsearch-model/spec/elasticsearch/model/naming_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/naming_spec.rb @@ -51,11 +51,6 @@ class DummyNamingModelInNamespace expect(::MyNamespace::DummyNamingModelInNamespace.new.index_name).to eq('my_namespace-dummy_naming_model_in_namespaces') end - it 'returns nil' do - expect(DummyNamingModel.document_type).to be_nil - expect(DummyNamingModel.new.document_type).to be_nil - end - describe '#index_name' do context 'when the index name is set on the class' do @@ -138,66 +133,4 @@ class DummyNamingModelInNamespace end end end - - describe '#document_type' do - - it 'returns nil' do - expect(DummyNamingModel.document_type).to be_nil - end - - context 'when the method is called with an argument' do - - before do - DummyNamingModel.document_type 'foo' - end - - it 'changes the document type' do - expect(DummyNamingModel.document_type).to eq('foo') - end - end - - context 'when the method is called on an instance' do - - let(:instance) do - DummyNamingModel.new - end - - before do - instance.document_type 'foobar_d' - end - - it 'changes the document type' do - expect(instance.document_type).to eq('foobar_d') - end - end - end - - describe '#document_type=' do - - context 'when the method is called on the class' do - - before do - DummyNamingModel.document_type = 'foo_z' - end - - it 'changes the document type' do - expect(DummyNamingModel.document_type).to eq('foo_z') - end - end - - context 'when the method is called on an instance' do - - let(:instance) do - DummyNamingModel.new - end - - before do - instance.document_type = 'foobar_b' - end - - it 'changes the document type' do - expect(instance.document_type).to eq('foobar_b') - end - end - end end diff --git a/elasticsearch-model/spec/elasticsearch/model/response/aggregations_spec.rb b/elasticsearch-model/spec/elasticsearch/model/response/aggregations_spec.rb index a455140ea..e840d949d 100644 --- a/elasticsearch-model/spec/elasticsearch/model/response/aggregations_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/response/aggregations_spec.rb @@ -22,7 +22,6 @@ before(:all) do class OriginClass def self.index_name; 'foo'; end - def self.document_type; 'bar'; end end end diff --git a/elasticsearch-model/spec/elasticsearch/model/response/base_spec.rb b/elasticsearch-model/spec/elasticsearch/model/response/base_spec.rb index d3459b93b..dd5ff2d26 100644 --- a/elasticsearch-model/spec/elasticsearch/model/response/base_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/response/base_spec.rb @@ -26,7 +26,6 @@ class DummyBaseClass class OriginClass def self.index_name; 'foo'; end - def self.document_type; 'bar'; end end end diff --git a/elasticsearch-model/spec/elasticsearch/model/response/pagination/kaminari_spec.rb b/elasticsearch-model/spec/elasticsearch/model/response/pagination/kaminari_spec.rb index 15ee6113c..af6091df2 100644 --- a/elasticsearch-model/spec/elasticsearch/model/response/pagination/kaminari_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/response/pagination/kaminari_spec.rb @@ -23,7 +23,6 @@ class ModelClass include ::Kaminari::ConfigurationMethods def self.index_name; 'foo'; end - def self.document_type; 'bar'; end end end @@ -58,7 +57,7 @@ def self.document_type; 'bar'; end context 'when page is called once' do let(:search_request) do - { index: index_field, from: 25, size: 25, q: '*', type: type_field} + { index: index_field, from: 25, size: 25, q: '*'} end before do @@ -75,11 +74,11 @@ def self.document_type; 'bar'; end context 'when page is called more than once' do let(:search_request_one) do - { index: index_field, from: 25, size: 25, q: '*', type: type_field} + { index: index_field, from: 25, size: 25, q: '*'} end let(:search_request_two) do - { index: index_field, from: 75, size: 25, q: '*', type: type_field} + { index: index_field, from: 75, size: 25, q: '*'} end before do diff --git a/elasticsearch-model/spec/elasticsearch/model/response/pagination/will_paginate_spec.rb b/elasticsearch-model/spec/elasticsearch/model/response/pagination/will_paginate_spec.rb index 25f1f0d1e..0f7303adf 100644 --- a/elasticsearch-model/spec/elasticsearch/model/response/pagination/will_paginate_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/response/pagination/will_paginate_spec.rb @@ -22,7 +22,6 @@ before(:all) do class ModelClass def self.index_name; 'foo'; end - def self.document_type; 'bar'; end def self.per_page 33 diff --git a/elasticsearch-model/spec/elasticsearch/model/response/records_spec.rb b/elasticsearch-model/spec/elasticsearch/model/response/records_spec.rb index 2a80dcfc6..a4e5e7072 100644 --- a/elasticsearch-model/spec/elasticsearch/model/response/records_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/response/records_spec.rb @@ -31,7 +31,6 @@ def foo; 'BAR'; end class DummyModel def self.index_name; 'foo'; end - def self.document_type; 'bar'; end def self.find(*args) DummyCollection.new diff --git a/elasticsearch-model/spec/elasticsearch/model/response/response_spec.rb b/elasticsearch-model/spec/elasticsearch/model/response/response_spec.rb index e9a423812..7186b4710 100644 --- a/elasticsearch-model/spec/elasticsearch/model/response/response_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/response/response_spec.rb @@ -22,7 +22,6 @@ before(:all) do class OriginClass def self.index_name; 'foo'; end - def self.document_type; 'bar'; end end end diff --git a/elasticsearch-model/spec/elasticsearch/model/response/results_spec.rb b/elasticsearch-model/spec/elasticsearch/model/response/results_spec.rb index f69db2c01..f944e1877 100644 --- a/elasticsearch-model/spec/elasticsearch/model/response/results_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/response/results_spec.rb @@ -22,7 +22,6 @@ before(:all) do class OriginClass def self.index_name; 'foo'; end - def self.document_type; 'bar'; end end end diff --git a/elasticsearch-model/spec/elasticsearch/model/searching_search_request_spec.rb b/elasticsearch-model/spec/elasticsearch/model/searching_search_request_spec.rb index 1f5e72bf2..1a7b4e413 100644 --- a/elasticsearch-model/spec/elasticsearch/model/searching_search_request_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/searching_search_request_spec.rb @@ -23,7 +23,6 @@ class ::DummySearchingModel extend Elasticsearch::Model::Searching::ClassMethods def self.index_name; 'foo'; end - def self.document_type; 'bar'; end end end @@ -44,7 +43,7 @@ def self.document_type; 'bar'; end context 'when the search definition is a simple query' do before do - expect(client).to receive(:search).with(index: 'foo', type: 'bar', q: 'foo').and_return({}) + expect(client).to receive(:search).with(index: 'foo', q: 'foo').and_return({}) end let(:search) do @@ -59,7 +58,7 @@ def self.document_type; 'bar'; end context 'when the search definition is a hash' do before do - expect(client).to receive(:search).with(index: 'foo', type: 'bar', body: { foo: 'bar' }).and_return({}) + expect(client).to receive(:search).with(index: 'foo', body: { foo: 'bar' }).and_return({}) end let(:search) do @@ -74,7 +73,7 @@ def self.document_type; 'bar'; end context 'when the search definition is a json string' do before do - expect(client).to receive(:search).with(index: 'foo', type: 'bar', body: '{"foo":"bar"}').and_return({}) + expect(client).to receive(:search).with(index: 'foo', body: '{"foo":"bar"}').and_return({}) end let(:search) do @@ -99,7 +98,7 @@ def to_hash; {foo: 'bar'}; end end before do - expect(client).to receive(:search).with(index: 'foo', type: 'bar', body: {foo: 'bar'}).and_return({}) + expect(client).to receive(:search).with(index: 'foo', body: {foo: 'bar'}).and_return({}) end let(:search) do @@ -114,7 +113,7 @@ def to_hash; {foo: 'bar'}; end context 'when extra options are specified' do before do - expect(client).to receive(:search).with(index: 'foo', type: 'bar', q: 'foo', size: 15).and_return({}) + expect(client).to receive(:search).with(index: 'foo', q: 'foo', size: 15).and_return({}) end let(:search) do diff --git a/elasticsearch-model/spec/elasticsearch/model/searching_spec.rb b/elasticsearch-model/spec/elasticsearch/model/searching_spec.rb index ccede7435..7f55209da 100644 --- a/elasticsearch-model/spec/elasticsearch/model/searching_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/searching_spec.rb @@ -24,7 +24,6 @@ class ::DummySearchingModel extend Elasticsearch::Model::Searching::ClassMethods def self.index_name; 'foo'; end - def self.document_type; 'bar'; end end end diff --git a/elasticsearch-model/spec/spec_helper.rb b/elasticsearch-model/spec/spec_helper.rb index 413b5f03e..dc3f1cd4d 100644 --- a/elasticsearch-model/spec/spec_helper.rb +++ b/elasticsearch-model/spec/spec_helper.rb @@ -30,6 +30,7 @@ end require 'yaml' require 'active_record' +require 'sqlite3' unless defined?(ELASTICSEARCH_URL) ELASTICSEARCH_URL = ENV['ELASTICSEARCH_URL'] || "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9200)}" diff --git a/elasticsearch-model/spec/support/app/answer.rb b/elasticsearch-model/spec/support/app/answer.rb index 9c58cc991..ec010e3d2 100644 --- a/elasticsearch-model/spec/support/app/answer.rb +++ b/elasticsearch-model/spec/support/app/answer.rb @@ -23,7 +23,6 @@ class Answer < ActiveRecord::Base JOIN_TYPE = 'answer'.freeze index_name 'questions_and_answers'.freeze - document_type 'doc'.freeze before_create :randomize_id diff --git a/elasticsearch-model/spec/support/app/article.rb b/elasticsearch-model/spec/support/app/article.rb index 2c122dd77..659d16cec 100644 --- a/elasticsearch-model/spec/support/app/article.rb +++ b/elasticsearch-model/spec/support/app/article.rb @@ -19,8 +19,6 @@ class ::Article < ActiveRecord::Base include Elasticsearch::Model include Elasticsearch::Model::Callbacks - document_type 'article' - settings index: {number_of_shards: 1, number_of_replicas: 0} do mapping do indexes :title, type: 'text', analyzer: 'snowball' diff --git a/elasticsearch-model/spec/support/app/namespaced_book.rb b/elasticsearch-model/spec/support/app/namespaced_book.rb index f6d9c838c..29949772a 100644 --- a/elasticsearch-model/spec/support/app/namespaced_book.rb +++ b/elasticsearch-model/spec/support/app/namespaced_book.rb @@ -20,8 +20,6 @@ class Book < ActiveRecord::Base include Elasticsearch::Model include Elasticsearch::Model::Callbacks - document_type 'book' - mapping { indexes :title } end end diff --git a/elasticsearch-model/spec/support/app/question.rb b/elasticsearch-model/spec/support/app/question.rb index 62a7d4550..fce543139 100644 --- a/elasticsearch-model/spec/support/app/question.rb +++ b/elasticsearch-model/spec/support/app/question.rb @@ -24,7 +24,6 @@ class Question < ActiveRecord::Base JOIN_METADATA = { join_field: JOIN_TYPE}.freeze index_name 'questions_and_answers'.freeze - document_type 'doc'.freeze mapping do indexes :title diff --git a/elasticsearch-persistence/README.md b/elasticsearch-persistence/README.md index e8cb0aa8a..1182e7931 100644 --- a/elasticsearch-persistence/README.md +++ b/elasticsearch-persistence/README.md @@ -194,7 +194,6 @@ class NoteRepository include Elasticsearch::Persistence::Repository::DSL index_name 'notes' - document_type 'note' klass Note settings number_of_shards: 1 do @@ -318,33 +317,6 @@ repository.index_name ``` -The `document_type` method specifies the Elasticsearch document type to use for storage, lookup and search. The default value is -'_doc'. Keep in mind that future versions of Elasticsearch will not allow you to set this yourself and will use the type, -'_doc'. - -```ruby -repository = NoteRepository.new(document_type: 'note') -repository.document_type -# => 'note' - -``` - -or with the DSL mixin: - -```ruby -class NoteRepository - include Elasticsearch::Persistence::Repository - include Elasticsearch::Persistence::Repository::DSL - - document_type 'note' -end - -repository = NoteRepository.new -repository.document_type -# => 'note' - -``` - The `klass` method specifies the Ruby class name to use when initializing objects from documents retrieved from the repository. If this value is not set, a Hash representation of the document will be returned instead. diff --git a/elasticsearch-persistence/elasticsearch-persistence.gemspec b/elasticsearch-persistence/elasticsearch-persistence.gemspec index a37232c93..b9d17978f 100644 --- a/elasticsearch-persistence/elasticsearch-persistence.gemspec +++ b/elasticsearch-persistence/elasticsearch-persistence.gemspec @@ -43,8 +43,8 @@ Gem::Specification.new do |s| s.add_dependency 'activemodel', '> 4' s.add_dependency 'activesupport', '> 4' - s.add_dependency 'elasticsearch', '~> 7' - s.add_dependency 'elasticsearch-model', '7.2.1' + s.add_dependency 'elasticsearch', '~> 8.7.0' + s.add_dependency 'elasticsearch-model', '~> 8.7.0' s.add_dependency 'hashie' s.add_development_dependency 'bundler' diff --git a/elasticsearch-persistence/examples/notes/application.rb b/elasticsearch-persistence/examples/notes/application.rb index 0f1724476..9b7bc88ae 100644 --- a/elasticsearch-persistence/examples/notes/application.rb +++ b/elasticsearch-persistence/examples/notes/application.rb @@ -75,7 +75,6 @@ class NoteRepository client Elasticsearch::Client.new url: ENV['ELASTICSEARCH_URL'], log: true index_name :notes - document_type :note mapping do indexes :text, analyzer: 'snowball' diff --git a/elasticsearch-persistence/lib/elasticsearch/persistence/repository.rb b/elasticsearch-persistence/lib/elasticsearch/persistence/repository.rb index 607de1769..e5fb23c13 100644 --- a/elasticsearch-persistence/lib/elasticsearch/persistence/repository.rb +++ b/elasticsearch-persistence/lib/elasticsearch/persistence/repository.rb @@ -58,7 +58,6 @@ module ClassMethods # @param [ Proc ] block A block to evaluate on the new repository instance. # # @option options [ Symbol, String ] :index_name The name of the index. - # @option options [ Symbol, String ] :document_type The type of documents persisted in this repository. # @option options [ Symbol, String ] :client The client used to handle requests to and from Elasticsearch. # @option options [ Symbol, String ] :klass The class used to instantiate an object when documents are # deserialized. The default is nil, in which case the raw document will be returned as a Hash. @@ -95,7 +94,6 @@ def create(options = {}, &block) # @param [ Hash ] options The options to use. # # @option options [ Symbol, String ] :index_name The name of the index. - # @option options [ Symbol, String ] :document_type The type of documents persisted in this repository. # @option options [ Symbol, String ] :client The client used to handle requests to and from Elasticsearch. # @option options [ Symbol, String ] :klass The class used to instantiate an object when documents are # deserialized. The default is nil, in which case the raw document will be returned as a Hash. @@ -121,19 +119,6 @@ def client Elasticsearch::Client.new end - # Get the document type used by the repository object. - # - # @example - # repository.document_type - # - # @return [ String, Symbol ] The repository's document type. - # - # @since 6.0.0 - def document_type - @document_type ||= @options[:document_type] || - __get_class_value(:document_type) - end - # Get the index name used by the repository. # # @example @@ -180,7 +165,6 @@ def klass def mapping(*args) @memoized_mapping ||= @options[:mapping] || (begin if _mapping = __get_class_value(:mapping) - _mapping.instance_variable_set(:@type, document_type) _mapping end end) || (super && @mapping) @@ -229,7 +213,7 @@ def index_exists?(*args) # # @since 6.0.0 def inspect - "#<#{self.class}:0x#{object_id} index_name=#{index_name} document_type=#{document_type} klass=#{klass}>" + "#<#{self.class}:0x#{object_id} index_name=#{index_name} klass=#{klass}>" end private diff --git a/elasticsearch-persistence/lib/elasticsearch/persistence/repository/dsl.rb b/elasticsearch-persistence/lib/elasticsearch/persistence/repository/dsl.rb index de2848071..f161af217 100644 --- a/elasticsearch-persistence/lib/elasticsearch/persistence/repository/dsl.rb +++ b/elasticsearch-persistence/lib/elasticsearch/persistence/repository/dsl.rb @@ -35,18 +35,6 @@ def self.included(base) # @since 6.0.0 module ClassMethods - # Get or set the class-level document type setting. - # - # @example - # MyRepository.document_type - # - # @return [ String, Symbol ] _type The repository's document type. - # - # @since 6.0.0 - def document_type(_type = nil) - @document_type ||= _type - end - # Get or set the class-level index name setting. # # @example diff --git a/elasticsearch-persistence/lib/elasticsearch/persistence/repository/find.rb b/elasticsearch-persistence/lib/elasticsearch/persistence/repository/find.rb index cdd50c042..281486a4a 100644 --- a/elasticsearch-persistence/lib/elasticsearch/persistence/repository/find.rb +++ b/elasticsearch-persistence/lib/elasticsearch/persistence/repository/find.rb @@ -64,7 +64,6 @@ def find(*args) # def exists?(id, options={}) request = { index: index_name, id: id } - request[:type] = document_type if document_type client.exists(request.merge(options)) end @@ -84,10 +83,9 @@ def exists?(id, options={}) # def __find_one(id, options={}) request = { index: index_name, id: id } - request[:type] = document_type if document_type document = client.get(request.merge(options)) deserialize(document) - rescue Elasticsearch::Transport::Transport::Errors::NotFound => e + rescue Elastic::Transport::Transport::Errors::NotFound => e raise DocumentNotFound, e.message, caller end @@ -95,7 +93,6 @@ def __find_one(id, options={}) # def __find_many(ids, options={}) request = { index: index_name, body: { ids: ids } } - request[:type] = document_type if document_type documents = client.mget(request.merge(options)) documents[DOCS].map do |document| deserialize(document) if document[FOUND] diff --git a/elasticsearch-persistence/lib/elasticsearch/persistence/repository/search.rb b/elasticsearch-persistence/lib/elasticsearch/persistence/repository/search.rb index 2aa7db725..db7788682 100644 --- a/elasticsearch-persistence/lib/elasticsearch/persistence/repository/search.rb +++ b/elasticsearch-persistence/lib/elasticsearch/persistence/repository/search.rb @@ -60,8 +60,7 @@ module Search # @return [Elasticsearch::Persistence::Repository::Response::Results] # def search(query_or_definition, options={}) - request = { index: index_name, - type: document_type } + request = { index: index_name } if query_or_definition.respond_to?(:to_hash) request[:body] = query_or_definition.to_hash elsif query_or_definition.is_a?(String) @@ -98,8 +97,7 @@ def search(query_or_definition, options={}) # def count(query_or_definition=nil, options={}) query_or_definition ||= { query: { match_all: {} } } - request = { index: index_name, - type: document_type } + request = { index: index_name } if query_or_definition.respond_to?(:to_hash) request[:body] = query_or_definition.to_hash diff --git a/elasticsearch-persistence/lib/elasticsearch/persistence/repository/store.rb b/elasticsearch-persistence/lib/elasticsearch/persistence/repository/store.rb index a8eeb1866..6f86c7036 100644 --- a/elasticsearch-persistence/lib/elasticsearch/persistence/repository/store.rb +++ b/elasticsearch-persistence/lib/elasticsearch/persistence/repository/store.rb @@ -40,7 +40,6 @@ def save(document, options={}) request = { index: index_name, id: id, body: serialized } - request[:type] = document_type if document_type client.index(request.merge(options)) end @@ -65,7 +64,6 @@ def update(document_or_id, options = {}) if document_or_id.is_a?(String) || document_or_id.is_a?(Integer) id = document_or_id body = options - type = document_type else document = serialize(document_or_id) id = __extract_id_from_document(document) @@ -74,9 +72,8 @@ def update(document_or_id, options = {}) else body = { doc: document }.merge(options) end - type = document.delete(:type) || document_type end - client.update(index: index_name, id: id, type: type, body: body) + client.update(index: index_name, id: id, body: body) end # Remove the serialized object or document with specified ID from Elasticsearch @@ -98,7 +95,7 @@ def delete(document_or_id, options = {}) serialized = serialize(document_or_id) id = __get_id_from_document(serialized) end - client.delete({ index: index_name, type: document_type, id: id }.merge(options)) + client.delete({ index: index_name, id: id }.merge(options)) end end end diff --git a/elasticsearch-persistence/spec/repository/find_spec.rb b/elasticsearch-persistence/spec/repository/find_spec.rb index 083ee4c25..564f1ad62 100644 --- a/elasticsearch-persistence/spec/repository/find_spec.rb +++ b/elasticsearch-persistence/spec/repository/find_spec.rb @@ -46,17 +46,6 @@ expect(repository.exists?('1')).to be(false) end end - - context 'when options are provided' do - - let(:id) do - repository.save(a: 1)['_id'] - end - - it 'applies the options' do - expect(repository.exists?(id, type: 'other_type')).to be(false) - end - end end describe '#find' do @@ -131,66 +120,5 @@ end end end - - context 'when options are provided' do - - context 'when a single id is passed' do - - let!(:id) do - repository.save(a: 1)['_id'] - end - - it 'applies the options' do - expect { - repository.find(id, type: 'none') - }.to raise_exception(Elasticsearch::Persistence::Repository::DocumentNotFound) - end - end - - context 'when an array of ids is passed' do - - let!(:ids) do - 3.times.collect do |i| - repository.save(a: i)['_id'] - end - end - - it 'applies the options' do - expect(repository.find(ids, type: 'none')).to eq([nil, nil, nil]) - end - end - - context 'when multiple ids are passed' do - - let!(:ids) do - 3.times.collect do |i| - repository.save(a: i)['_id'] - end - end - - it 'applies the options' do - expect(repository.find(*ids, type: 'none')).to eq([nil, nil, nil]) - end - end - end - - context 'when a document_type is defined on the class' do - - let(:repository) do - MyTestRepository.new(document_type:'other_type', client: DEFAULT_CLIENT, index_name: 'test') - end - - let!(:ids) do - 3.times.collect do |i| - repository.save(a: i)['_id'] - end - end - - it 'uses the document type in the query' do - expect(repository.find(ids)).to eq([{ 'a' =>0 }, - { 'a' => 1 }, - { 'a' => 2 }]) - end - end end end diff --git a/elasticsearch-persistence/spec/repository/search_spec.rb b/elasticsearch-persistence/spec/repository/search_spec.rb index 8e94ecc1d..e46c7f5db 100644 --- a/elasticsearch-persistence/spec/repository/search_spec.rb +++ b/elasticsearch-persistence/spec/repository/search_spec.rb @@ -57,69 +57,6 @@ }.to raise_exception(ArgumentError) end end - - context 'when options are provided' do - - context 'when a query definition is provided as a hash' do - - it 'uses the default document type' do - expect(repository.search({ query: { match: { name: 'user' } } }, type: 'other').first).to be_nil - end - end - - context 'when a query definition is provided as a string' do - - it 'uses the default document type' do - expect(repository.search('user', type: 'other').first).to be_nil - end - end - - context 'when the query definition is neither a String nor a Hash' do - - it 'raises an ArgumentError' do - expect { - repository.search(1) - }.to raise_exception(ArgumentError) - end - end - end - end - - context 'when the repository does have a type set' do - - let(:repository) do - MyTestRepository.new(document_type: 'other_note') - end - - before do - repository.save({ name: 'user' }, refresh: true) - end - - context 'when options are provided' do - - context 'when a query definition is provided as a hash' do - - it 'uses the options' do - expect(repository.search({ query: { match: { name: 'user' } } }, type: 'other').first).to be_nil - end - end - - context 'when a query definition is provided as a string' do - - it 'uses the options' do - expect(repository.search('user', type: 'other').first).to be_nil - end - end - - context 'when the query definition is neither a String nor a Hash' do - - it 'raises an ArgumentError' do - expect { - repository.search(1) - }.to raise_exception(ArgumentError) - end - end - end end end @@ -148,51 +85,6 @@ expect(repository.count('user')).to eq(1) end end - - context 'when options are provided' do - - context 'when a query definition is provided as a hash' do - - it 'uses the options' do - expect(repository.count({ query: { match: { name: 'user' } } }, type: 'other')).to eq(0) - end - end - - context 'when a query definition is provided as a string' do - - it 'uses the options' do - expect(repository.count('user', type: 'other')).to eq(0) - end - end - end - end - - context 'when the repository does have a type set' do - - let(:repository) do - MyTestRepository.new(document_type: 'other_note') - end - - before do - repository.save({ name: 'user' }, refresh: true) - end - - context 'when options are provided' do - - context 'when a query definition is provided as a hash' do - - it 'uses the options' do - expect(repository.count({ query: { match: { name: 'user' } } }, type: 'other')).to eq(0) - end - end - - context 'when a query definition is provided as a string' do - - it 'uses the options' do - expect(repository.count('user', type: 'other')).to eq(0) - end - end - end end end end diff --git a/elasticsearch-persistence/spec/repository/store_spec.rb b/elasticsearch-persistence/spec/repository/store_spec.rb index bebf810aa..56b333147 100644 --- a/elasticsearch-persistence/spec/repository/store_spec.rb +++ b/elasticsearch-persistence/spec/repository/store_spec.rb @@ -70,20 +70,6 @@ def serialize(document) expect(repository.find(response['_id'])).to eq('b' => 1) end end - - context 'when options are provided' do - - let!(:response) do - repository.save(document, type: 'other_note') - end - - it 'saves the document using the options' do - expect { - repository.find(response['_id']) - }.to raise_exception(Elasticsearch::Persistence::Repository::DocumentNotFound) - expect(repository.find(response['_id'], type: 'other_note')).to eq('a' => 1) - end - end end describe '#update' do @@ -242,7 +228,7 @@ def to_hash it 'raises an exception' do expect { repository.update(1, doc: { text: 'testing_2' }) - }.to raise_exception(Elasticsearch::Transport::Transport::Errors::NotFound) + }.to raise_exception(Elastic::Transport::Transport::Errors::NotFound) end context 'when upsert is provided' do @@ -262,7 +248,7 @@ def to_hash it 'raises an exception' do expect { repository.update(id: 1, text: 'testing_2') - }.to raise_exception(Elasticsearch::Transport::Transport::Errors::NotFound) + }.to raise_exception(Elastic::Transport::Transport::Errors::NotFound) end context 'when upsert is provided' do @@ -331,13 +317,13 @@ def to_hash context 'when the document does not exist' do before do - repository.create_index!(include_type_name: true) + repository.create_index!() end it 'raises an exception' do expect { repository.delete(1) - }.to raise_exception(Elasticsearch::Transport::Transport::Errors::NotFound) + }.to raise_exception(Elastic::Transport::Transport::Errors::NotFound) end end end diff --git a/elasticsearch-persistence/spec/repository_spec.rb b/elasticsearch-persistence/spec/repository_spec.rb index 05aeb1f53..c7a439cb4 100644 --- a/elasticsearch-persistence/spec/repository_spec.rb +++ b/elasticsearch-persistence/spec/repository_spec.rb @@ -37,21 +37,10 @@ class RepositoryWithoutDSL expect(RepositoryWithoutDSL.create).to be_a(RepositoryWithoutDSL) end - context 'when options are provided' do - - let(:repository) do - RepositoryWithoutDSL.create(document_type: 'note') - end - - it 'sets the options on the instance' do - expect(repository.document_type).to eq('note') - end - end - context 'when a block is passed' do let(:repository) do - RepositoryWithoutDSL.create(document_type: 'note') do + RepositoryWithoutDSL.create do mapping dynamic: 'strict' do indexes :foo end @@ -59,7 +48,7 @@ class RepositoryWithoutDSL end it 'executes the block on the instance' do - expect(repository.mapping.to_hash).to eq(note: { dynamic: 'strict', properties: { foo: { type: 'text' } } }) + expect(repository.mapping.to_hash).to eq(dynamic: 'strict', properties: { foo: { type: 'text' } }) end context 'when options are provided in the args and set in the block' do @@ -124,17 +113,13 @@ class RepositoryWithoutDSL end let(:repository) do - RepositoryWithoutDSL.new(client: client, document_type: 'user', index_name: 'users', klass: Array) + RepositoryWithoutDSL.new(client: client, index_name: 'users', klass: Array) end it 'sets the client' do expect(repository.client).to be(client) end - it 'sets document type' do - expect(repository.document_type).to eq('user') - end - it 'sets index name' do expect(repository.index_name).to eq('users') end @@ -152,7 +137,6 @@ class RepositoryWithDSL include Elasticsearch::Persistence::Repository include Elasticsearch::Persistence::Repository::DSL - document_type 'note' index_name 'notes_repo' klass Hash client DEFAULT_CLIENT @@ -229,26 +213,6 @@ class RepositoryWithDSL end end - context '#document_type' do - - it 'allows the value to be set only once on the class' do - RepositoryWithDSL.document_type('other_note') - expect(RepositoryWithDSL.document_type).to eq('note') - end - - it 'sets the value at the class level' do - expect(RepositoryWithDSL.document_type).to eq('note') - end - - it 'sets the value as the default at the instance level' do - expect(RepositoryWithDSL.new.document_type).to eq('note') - end - - it 'allows the value to be overridden with options on the instance' do - expect(RepositoryWithDSL.new(document_type: 'other_note').document_type).to eq('other_note') - end - end - context '#index_name' do it 'allows the value to be set only once on the class' do @@ -279,7 +243,7 @@ class RepositoryWithDSL before do begin; repository.delete_index!; rescue; end - repository.create_index!(include_type_name: true) + repository.create_index!() end it 'creates the index' do @@ -334,7 +298,7 @@ class RepositoryWithDSL end before do - repository.create_index!(include_type_name: true) + repository.create_index!() end it 'refreshes the index' do @@ -361,7 +325,7 @@ class RepositoryWithDSL end before do - repository.create_index!(include_type_name: true) + repository.create_index!() end it 'determines if the index exists' do @@ -389,11 +353,10 @@ class RepositoryWithDSL describe '#mapping' do let(:expected_mapping) do - { note: { dynamic: 'strict', + { dynamic: 'strict', properties: { foo: { type: 'object', properties: { bar: { type: 'text' } } }, baz: { type: 'text' } } - } } end @@ -408,22 +371,6 @@ class RepositoryWithDSL it 'allows the value to be overridden with options on the instance' do expect(RepositoryWithDSL.new(mapping: double('mapping', to_hash: { note: {} })).mapping.to_hash).to eq(note: {}) end - - context 'when the instance has a different document type' do - - let(:expected_mapping) do - { other_note: { dynamic: 'strict', - properties: { foo: { type: 'object', - properties: { bar: { type: 'text' } } }, - baz: { type: 'text' } } - } - } - end - - it 'updates the mapping to use the document type' do - expect(RepositoryWithDSL.new(document_type: 'other_note').mapping.to_hash).to eq(expected_mapping) - end - end end describe '#settings' do @@ -490,19 +437,6 @@ class RepositoryWithoutDSL end end - context '#document_type' do - - it 'does not define the method at the class level' do - expect { - RepositoryWithoutDSL.document_type - }.to raise_exception(NoMethodError) - end - - it 'allows the value to be overridden with options on the instance' do - expect(RepositoryWithoutDSL.new(document_type: 'notes').document_type).to eq('notes') - end - end - context '#index_name' do it 'does not define the method at the class level' do @@ -546,26 +480,6 @@ class RepositoryWithoutDSL let(:repository) do RepositoryWithoutDSL.new(client: DEFAULT_CLIENT, document_type: 'mytype') end - - context 'when the server is version >= 7.0', if: server_version > '7.0' do - - context 'when the include_type_name option is specified' do - - it 'creates an index' do - repository.create_index!(include_type_name: true) - expect(repository.index_exists?).to eq(true) - end - end - - context 'when the include_type_name option is not specified' do - - it 'raises an error' do - expect { - repository.create_index! - }.to raise_exception(Elasticsearch::Transport::Transport::Errors::BadRequest) - end - end - end end end @@ -582,7 +496,7 @@ class RepositoryWithoutDSL end it 'deletes an index' do - repository.create_index!(include_type_name: true) + repository.create_index!() repository.delete_index! expect(repository.index_exists?).to eq(false) end @@ -605,7 +519,7 @@ class RepositoryWithoutDSL end it 'refreshes an index' do - repository.create_index!(include_type_name: true) + repository.create_index!() expect(repository.refresh_index!['_shards']).to be_a(Hash) end end @@ -627,7 +541,7 @@ class RepositoryWithoutDSL end it 'returns whether the index exists' do - repository.create_index!(include_type_name: true) + repository.create_index!() expect(repository.index_exists?).to be(true) end end @@ -651,11 +565,10 @@ class RepositoryWithoutDSL context 'when a block is passed to the create method' do let(:expected_mapping) do - { note: { dynamic: 'strict', + { dynamic: 'strict', properties: { foo: { type: 'object', properties: { bar: { type: 'text' } } }, baz: { type: 'text' } } - } } end @@ -725,11 +638,10 @@ class RepositoryWithoutDSL context 'when a mapping is set in the block as well' do let(:expected_mapping) do - { note: { dynamic: 'strict', + { dynamic: 'strict', properties: { foo: { type: 'object', properties: { bar: { type: 'text' } } }, baz: { type: 'text' } } - } } end diff --git a/elasticsearch-persistence/spec/spec_helper.rb b/elasticsearch-persistence/spec/spec_helper.rb index 6e5f58402..e577d3808 100644 --- a/elasticsearch-persistence/spec/spec_helper.rb +++ b/elasticsearch-persistence/spec/spec_helper.rb @@ -47,7 +47,7 @@ class MyTestRepository # The default repository to be used by tests. # # @since 6.0.0 -DEFAULT_REPOSITORY = MyTestRepository.new(index_name: 'my_test_repository', document_type: 'test') +DEFAULT_REPOSITORY = MyTestRepository.new(index_name: 'my_test_repository') # Get the Elasticsearch server version. # diff --git a/elasticsearch-rails/elasticsearch-rails.gemspec b/elasticsearch-rails/elasticsearch-rails.gemspec index 0ba3f2b22..353dafb83 100644 --- a/elasticsearch-rails/elasticsearch-rails.gemspec +++ b/elasticsearch-rails/elasticsearch-rails.gemspec @@ -52,7 +52,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'minitest' s.add_development_dependency 'mocha' s.add_development_dependency 'pry' - s.add_development_dependency 'rails', '> 3.1' + s.add_development_dependency 'rails', '~> 7' s.add_development_dependency 'rake', '~> 12' s.add_development_dependency 'require-prof' s.add_development_dependency 'shoulda-context' diff --git a/elasticsearch-rails/lib/rails/templates/indexer.rb b/elasticsearch-rails/lib/rails/templates/indexer.rb index 1ea1d9b6c..4ba92a45e 100644 --- a/elasticsearch-rails/lib/rails/templates/indexer.rb +++ b/elasticsearch-rails/lib/rails/templates/indexer.rb @@ -37,7 +37,7 @@ def perform(operation, klass, record_id, options={}) record.__elasticsearch__.client = Client record.__elasticsearch__.__send__ "#{operation}_document" when /delete/ - Client.delete index: klass.constantize.index_name, type: klass.constantize.document_type, id: record_id + Client.delete index: klass.constantize.index_name, id: record_id else raise ArgumentError, "Unknown operation '#{operation}'" end end diff --git a/elasticsearch-rails/spec/instrumentation_spec.rb b/elasticsearch-rails/spec/instrumentation_spec.rb index 3fcbc5916..62ead69e5 100644 --- a/elasticsearch-rails/spec/instrumentation_spec.rb +++ b/elasticsearch-rails/spec/instrumentation_spec.rb @@ -24,7 +24,6 @@ class DummyInstrumentationModel extend Elasticsearch::Model::Searching::ClassMethods def self.index_name; 'foo'; end - def self.document_type; 'bar'; end end end @@ -67,8 +66,7 @@ def self.document_type; 'bar'; end { klass: 'DummyInstrumentationModel', name: 'Search', search: { body: query, - index: 'foo', - type: 'bar' } }).and_return({}) + index: 'foo'} }).and_return({}) end let(:query) do