From b71d5a9dfb1a5212cbad8b6f9321a1e0a6726579 Mon Sep 17 00:00:00 2001 From: Fernando Briano Date: Tue, 20 Jun 2023 16:29:00 +0100 Subject: [PATCH] Removing type related code --- .../lib/elasticsearch/model.rb | 2 +- .../lib/elasticsearch/model/importing.rb | 3 - .../lib/elasticsearch/model/indexing.rb | 11 +-- .../elasticsearch/model/response/result.rb | 6 -- .../lib/elasticsearch/model/searching.rb | 5 +- .../adapters/active_record/basic_spec.rb | 14 +--- .../active_record/namespaced_model_spec.rb | 6 +- .../elasticsearch/model/importing_spec.rb | 16 +---- .../spec/elasticsearch/model/indexing_spec.rb | 1 - .../spec/elasticsearch/model/naming_spec.rb | 68 ------------------- .../elasticsearch/model/response/base_spec.rb | 1 - .../response/pagination/kaminari_spec.rb | 7 +- .../model/response/response_spec.rb | 1 - .../model/response/result_spec.rb | 16 ----- .../model/searching_search_request_spec.rb | 11 ++- .../spec/support/app/answer.rb | 1 - .../spec/support/app/article.rb | 2 - .../spec/support/app/article_no_type.rb | 2 +- .../spec/support/app/namespaced_book.rb | 2 - .../spec/support/app/question.rb | 1 - .../spec/repository/store_spec.rb | 6 +- 21 files changed, 22 insertions(+), 160 deletions(-) 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 b9f9ea392..3060e178a 100644 --- a/elasticsearch-model/lib/elasticsearch/model/importing.rb +++ b/elasticsearch-model/lib/elasticsearch/model/importing.rb @@ -59,7 +59,6 @@ module ClassMethods # "index" => { # "error" => 'FAILED', # "_index" => "test", - # "_type" => "_doc", # "_id" => '1', # "_version" => 1, # "result" => "foo", @@ -138,7 +137,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' @@ -158,7 +156,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..f270a26b4 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? @@ -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/response/result.rb b/elasticsearch-model/lib/elasticsearch/model/response/result.rb index 5e102c2b3..d293e6efa 100644 --- a/elasticsearch-model/lib/elasticsearch/model/response/result.rb +++ b/elasticsearch-model/lib/elasticsearch/model/response/result.rb @@ -40,12 +40,6 @@ def id @result['_id'] end - # Return document `_type` as `_type` - # - def type - @result['_type'] - end - # Delegate methods to `@result` or `@result._source` # def method_missing(name, *arguments) 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/spec/elasticsearch/model/adapters/active_record/basic_spec.rb b/elasticsearch-model/spec/elasticsearch/model/adapters/active_record/basic_spec.rb index 9c62a03a6..5dc91da9e 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 @@ -66,7 +66,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) @@ -159,19 +159,7 @@ end end - describe '#id' do - - let(:search_result) do - Article.search('title:test') - end - - it 'returns the type' do - expect(search_result.results.first.type).to eq('article') - end - end - describe '#each_with_hit' do - let(:search_result) do Article.search('title:test') end 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/importing_spec.rb b/elasticsearch-model/spec/elasticsearch/model/importing_spec.rb index 343e04d00..438d0c9e9 100644 --- a/elasticsearch-model/spec/elasticsearch/model/importing_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/importing_spec.rb @@ -57,7 +57,6 @@ def importing_mixin describe '#import' do 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) @@ -148,7 +147,7 @@ def importing_mixin context 'when a different index name is provided' do 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 @@ -156,17 +155,6 @@ def importing_mixin end end - context 'when a different document type is provided' do - 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) - end - - it 'uses the alternate index name' do - expect(DummyImportingModel.import(type: 'my-new-type')).to eq(0) - end - end - context 'the transform method' do before do expect(DummyImportingModel).to receive(:client).and_return(client) @@ -215,7 +203,7 @@ def importing_mixin context 'when a pipeline is provided as an options' do 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 b4d5777da..5836bd2a6 100644 --- a/elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb @@ -38,7 +38,6 @@ class NotFound < Exception; end end describe 'the Settings class' do - it 'should be convertible to a hash' do expect(Elasticsearch::Model::Indexing::Settings.new(foo: 'bar').to_hash).to eq(foo: 'bar') end diff --git a/elasticsearch-model/spec/elasticsearch/model/naming_spec.rb b/elasticsearch-model/spec/elasticsearch/model/naming_spec.rb index 57a53b8d7..917bc099c 100644 --- a/elasticsearch-model/spec/elasticsearch/model/naming_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/naming_spec.rb @@ -51,13 +51,7 @@ 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 before do @@ -138,66 +132,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/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..cb01c86cb 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/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/result_spec.rb b/elasticsearch-model/spec/elasticsearch/model/response/result_spec.rb index c3c73fec6..cf5abd38f 100644 --- a/elasticsearch-model/spec/elasticsearch/model/response/result_spec.rb +++ b/elasticsearch-model/spec/elasticsearch/model/response/result_spec.rb @@ -44,23 +44,7 @@ end end - describe '#type' do - - let(:result) do - described_class.new(foo: 'bar', _type: 'baz', _source: { type: 'BAM' }) - end - - it 'returns the _type field' do - expect(result.type).to eq('baz') - end - - it 'provides access to the source type field' do - expect(result._source.type).to eq('BAM') - end - end - describe 'method delegation' do - let(:result) do described_class.new(foo: 'bar', _source: { bar: { bam: 'baz' } }) 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/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/article_no_type.rb b/elasticsearch-model/spec/support/app/article_no_type.rb index d3cb6b4e3..9e6b8443f 100644 --- a/elasticsearch-model/spec/support/app/article_no_type.rb +++ b/elasticsearch-model/spec/support/app/article_no_type.rb @@ -21,7 +21,7 @@ class ::ArticleNoType < ActiveRecord::Base settings index: {number_of_shards: 1, number_of_replicas: 0} do mapping do - indexes :title, type: 'text', analyzer: 'snowball' + indexes :title, analyzer: 'snowball' indexes :body, type: 'text' indexes :clicks, type: 'integer' indexes :created_at, type: 'date' 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/spec/repository/store_spec.rb b/elasticsearch-persistence/spec/repository/store_spec.rb index 92b7035e7..82e1d3b01 100644 --- a/elasticsearch-persistence/spec/repository/store_spec.rb +++ b/elasticsearch-persistence/spec/repository/store_spec.rb @@ -74,14 +74,14 @@ def serialize(document) context 'when options are provided' do let!(:response) do - repository.save(document, type: 'other_note') + repository.save(document) 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) + expect(repository.find(response['_id'])).to eq('a' => 1) end end end @@ -331,7 +331,7 @@ 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