From 8259317cc2e6a333962e4c68b8b557f2a75a2f52 Mon Sep 17 00:00:00 2001 From: Ivan Rabotyaga Date: Tue, 2 Mar 2021 13:05:30 +0300 Subject: [PATCH] Drop support for Elasticsearch 6.x --- .circleci/config.yml | 26 ---- CHANGELOG.md | 7 + README.md | 1 + lib/chewy/fields/root.rb | 3 +- lib/chewy/index.rb | 19 +-- lib/chewy/index/actions.rb | 4 +- lib/chewy/index/aliases.rb | 4 +- lib/chewy/search/loader.rb | 14 +- lib/chewy/search/parameters/indices.rb | 69 ++------- lib/chewy/search/parameters/types.rb | 20 --- lib/chewy/search/request.rb | 60 +++----- lib/chewy/search/response.rb | 2 +- lib/chewy/search/scrolling.rb | 2 +- lib/chewy/stash.rb | 7 +- lib/chewy/type/import/bulk_request.rb | 3 +- lib/chewy/type/import/journal_builder.rb | 3 +- lib/chewy/type/import/routine.rb | 4 +- lib/chewy/type/mapping.rb | 2 +- lib/chewy/type/syncer.rb | 5 +- lib/chewy/version.rb | 2 +- migration_guide.md | 9 +- spec/chewy/fields/base_spec.rb | 8 +- spec/chewy/fields/root_spec.rb | 8 +- spec/chewy/index/specification_spec.rb | 26 ++-- spec/chewy/index_spec.rb | 4 +- spec/chewy/journal_spec.rb | 8 +- spec/chewy/runtime_spec.rb | 2 +- spec/chewy/search/loader_spec.rb | 16 --- spec/chewy/search/parameters/indices_spec.rb | 135 ++++-------------- spec/chewy/search/parameters/types_spec.rb | 5 - spec/chewy/search/request_spec.rb | 39 ++--- spec/chewy/search/scrolling_spec.rb | 10 +- spec/chewy/search_spec.rb | 4 +- spec/chewy/type/import/bulk_request_spec.rb | 6 - .../chewy/type/import/journal_builder_spec.rb | 4 - spec/chewy/type/import_spec.rb | 4 +- spec/chewy/type/mapping_spec.rb | 42 +----- 37 files changed, 140 insertions(+), 447 deletions(-) delete mode 100644 lib/chewy/search/parameters/types.rb delete mode 100644 spec/chewy/search/parameters/types_spec.rb diff --git a/.circleci/config.yml b/.circleci/config.yml index 03f9a6a7f..b44179a2a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,8 +23,6 @@ workflows: - rspec-ruby-27-activerecord52 - rspec-ruby-27-mongoid - rspec-ruby-30-activerecord61 - - rspec-ruby-27-activerecord61-es6 - - rspec-ruby-30-activerecord61-es6 commands: rspec-test: @@ -214,27 +212,3 @@ jobs: GEMFILE: gemfiles/rails.6.1.activerecord.gemfile steps: - rspec-test - - rspec-ruby-27-activerecord61-es6: - docker: - - image: circleci/ruby:2.7 - - image: docker.elastic.co/elasticsearch/elasticsearch:6.8.13 - environment: - <<: *es-env - working_directory: ~/repo - environment: - GEMFILE: gemfiles/rails.6.1.activerecord.gemfile - steps: - - rspec-test - - rspec-ruby-30-activerecord61-es6: - docker: - - image: circleci/ruby:3.0 - - image: docker.elastic.co/elasticsearch/elasticsearch:6.8.13 - environment: - <<: *es-env - working_directory: ~/repo - environment: - GEMFILE: gemfiles/rails.6.1.activerecord.gemfile - steps: - - rspec-test diff --git a/CHANGELOG.md b/CHANGELOG.md index 0703e5441..423fd0c7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ ### Changes +### Bugs Fixed + +## 7.1.0 (TODO) + +### Changes + + * [TODO](): **(Breaking)** Drop support for Elasticsearch 6.x ([@rabotyaga][]) * [#765](https://github.com/toptal/chewy/pull/765): Fix ruby 2.7 warnings in rake tasks ([@aglushkov][]) ### Bugs Fixed diff --git a/README.md b/README.md index 3a31309ac..a8a9be931 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ Chewy is compatible with MRI 2.5-3.0ยน. | Chewy version | Elasticsearch version | | ------------- | ---------------------------------- | +| 7.1.x | 7.x | | 7.0.0 | 6.8, 7.x | | 6.0.0 | 5.x, 6.x | | 5.x | 5.x, limited support for 1.x & 2.x | diff --git a/lib/chewy/fields/root.rb b/lib/chewy/fields/root.rb index 3e25f8cdb..e97c171fa 100644 --- a/lib/chewy/fields/root.rb +++ b/lib/chewy/fields/root.rb @@ -29,8 +29,7 @@ def mappings_hash mappings[name][:dynamic_templates].concat dynamic_templates end - mappings[name][:_parent] = parent.is_a?(Hash) ? parent : {type: parent} if parent - mappings + mappings[name] end def dynamic_template(*args) diff --git a/lib/chewy/index.rb b/lib/chewy/index.rb index b05a9b60d..48b940aa8 100644 --- a/lib/chewy/index.rb +++ b/lib/chewy/index.rb @@ -152,23 +152,12 @@ def define_type(target, options = {}, &block) self.type_hash = type_hash.merge(type_class.type_name => type_class) end - # Types method has double usage. - # If no arguments are passed - it returns array of defined types: + # Returns defined type: # - # UsersIndex.types # => [UsersIndex::Admin, UsersIndex::Manager, UsersIndex::User] + # UsersIndex.types # => [UsersIndex::User] # - # If arguments are passed it treats like a part of chainable query DSL and - # adds types array for index to select. - # - # UsersIndex.filters { name =~ 'ro' }.types(:admin, :manager) - # UsersIndex.types(:admin, :manager).filters { name =~ 'ro' } # the same as the first example - # - def types(*args) - if args.present? - all.types(*args) - else - type_hash.values - end + def types + type_hash.values end # Returns defined types names: diff --git a/lib/chewy/index/actions.rb b/lib/chewy/index/actions.rb index 9183b8927..ed25d4d00 100644 --- a/lib/chewy/index/actions.rb +++ b/lib/chewy/index/actions.rb @@ -59,9 +59,7 @@ def create!(suffix = nil, **options) body = specification_hash body[:aliases] = {general_name => {}} if options[:alias] && suffixed_name != general_name - args = {index: suffixed_name, body: body} - args[:include_type_name] = true if Runtime.version >= '6.7.0' - result = client.indices.create(**args) + result = client.indices.create(index: suffixed_name, body: body) Chewy.wait_for_status if result result diff --git a/lib/chewy/index/aliases.rb b/lib/chewy/index/aliases.rb index 21feebf8d..cfcf74732 100644 --- a/lib/chewy/index/aliases.rb +++ b/lib/chewy/index/aliases.rb @@ -5,9 +5,7 @@ module Aliases module ClassMethods def indexes - get_args = {index: index_name} - get_args[:include_type_name] = true if Runtime.version >= '6.7.0' - indexes = empty_if_not_found { client.indices.get(**get_args).keys } + indexes = empty_if_not_found { client.indices.get(index: index_name).keys } indexes += empty_if_not_found { client.indices.get_alias(name: index_name).keys } indexes.compact.uniq end diff --git a/lib/chewy/search/loader.rb b/lib/chewy/search/loader.rb index cab2798ff..1a86d07bb 100644 --- a/lib/chewy/search/loader.rb +++ b/lib/chewy/search/loader.rb @@ -9,14 +9,10 @@ module Search # @see Chewy::Search::Scrolling#scroll_objects class Loader # @param indexes [Array] list of indexes to lookup types - # @param only [Array] list of selected type names to load - # @param except [Array] list of type names which will not be loaded # @param options [Hash] adapter-specific load options # @see Chewy::Type::Adapter::Base#load - def initialize(indexes: [], only: [], except: [], **options) + def initialize(indexes: [], **options) @indexes = indexes - @only = Array.wrap(only).map(&:to_s) - @except = Array.wrap(except).map(&:to_s) @options = options end @@ -31,7 +27,7 @@ def derive_type(index, type) (@derive_type ||= {})[[index, type]] ||= begin index_class = derive_index(index) raise Chewy::UnderivableType, "Can not find index named `#{index}`" unless index_class - index_class.type_hash[type] or raise Chewy::UnderivableType, "Index `#{index}` doesn`t have type named `#{type}`" + index_class.type_hash.values.first end end @@ -48,8 +44,6 @@ def derive_type(index, type) def load(hits) hit_groups = hits.group_by { |hit| [hit['_index'], hit['_type']] } loaded_objects = hit_groups.each_with_object({}) do |((index_name, type_name), hit_group), result| - next if skip_type?(type_name) - type = derive_type(index_name, type_name) ids = hit_group.map { |hit| hit['_id'] } loaded = type.adapter.load(ids, **@options.merge(_type: type)) @@ -74,10 +68,6 @@ def derive_index(index_name) def indexes_hash @indexes_hash ||= @indexes.index_by(&:index_name) end - - def skip_type?(type_name) - @except.include?(type_name) || @only.present? && !@only.include?(type_name) - end end end end diff --git a/lib/chewy/search/parameters/indices.rb b/lib/chewy/search/parameters/indices.rb index 8d0fd1d7f..dc3dc28ca 100644 --- a/lib/chewy/search/parameters/indices.rb +++ b/lib/chewy/search/parameters/indices.rb @@ -3,70 +3,48 @@ module Chewy module Search class Parameters - # Stores indices and/or types to query. + # Stores indices to query. # Renders it to lists of string accepted by ElasticSearch # API. # - # The semantics behind it can be described in the - # following statements: - # 1. If index is added to the storage, no matter, a class + # If index is added to the storage, no matter, a class # or a string/symbol, it gets appended to the list. - # 2. If type is added to the storage, it filters out types - # assigned via indices. - # 3. But when a type class with non-existing index is added, - # this index got also added to the list if indices. - # 4. In cases when of an index identifier added, type - # indetifiers also got appended instead of filtering. class Indices < Storage # Two index storages are equal if they produce the # same output on render. # # @see Chewy::Search::Parameters::Storage#== # @param other [Chewy::Search::Parameters::Storage] any storage instance - # @return [true, false] the result of comparision + # @return [true, false] the result of comparison def ==(other) super || other.class == self.class && other.render == render end - # Just adds types to types and indices to indices. + # Just adds indices to indices. # # @see Chewy::Search::Parameters::Storage#update! - # @param other_value [{Symbol => Array}] any acceptable storage value - # @return [{Symbol => Array}] updated value + # @param other_value [{Symbol => Array}] any acceptable storage value + # @return [{Symbol => Array}] updated value def update!(other_value) new_value = normalize(other_value) - @value = { - indices: value[:indices] | new_value[:indices], - types: value[:types] | new_value[:types] - } + @value = {indices: value[:indices] | new_value[:indices]} end - # Returns desired index and type names. + # Returns desired index names. # # @see Chewy::Search::Parameters::Storage#render # @return [{Symbol => Array}] rendered value with the parameter name def render - { - index: index_names.uniq.sort, - type: type_names.uniq.sort - }.reject { |_, v| v.blank? } + {index: index_names.uniq.sort}.reject { |_, v| v.blank? } end # Returns index classes used for the request. - # No strings/symbos included. + # No strings/symbols included. # # @return [Array] a list of index classes def indices - index_classes | type_classes.map(&:index) - end - - # Returns type classes used for the request. - # No strings/symbos included. - # - # @return [Array] a list of types classes - def types - type_classes | (index_classes - type_classes.map(&:index)).flat_map(&:types) + index_classes end private @@ -78,10 +56,7 @@ def initialize_clone(origin) def normalize(value) value ||= {} - { - indices: Array.wrap(value[:indices]).flatten.compact, - types: Array.wrap(value[:types]).flatten.compact - } + {indices: Array.wrap(value[:indices]).flatten.compact} end def index_classes @@ -97,26 +72,6 @@ def index_identifiers def index_names indices.map(&:index_name) | index_identifiers.map(&:to_s) end - - def type_classes - value[:types].select do |klass| - klass.is_a?(Class) && klass < Chewy::Type - end - end - - def type_identifiers - value[:types] - type_classes - end - - def type_names - type_names = types.map(&:type_name) - - if index_identifiers.blank? && type_identifiers.present? - (type_names & type_identifiers.map(&:to_s)).presence || type_names - else - type_names | type_identifiers.map(&:to_s) - end - end end end end diff --git a/lib/chewy/search/parameters/types.rb b/lib/chewy/search/parameters/types.rb deleted file mode 100644 index 3e9465096..000000000 --- a/lib/chewy/search/parameters/types.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'chewy/search/parameters/storage' - -module Chewy - module Search - class Parameters - # A standard string array storage with one exception: rendering is empty. - # - # @see Chewy::Search::Parameters::StringArrayStorage - class Types < Storage - include StringArrayStorage - - # Doesn't render anything, has specialized rendering logic in - # {Chewy::Search::Request} - # - # @return [nil] - def render; end - end - end - end -end diff --git a/lib/chewy/search/request.rb b/lib/chewy/search/request.rb index 440f92f1f..e151a8936 100644 --- a/lib/chewy/search/request.rb +++ b/lib/chewy/search/request.rb @@ -41,7 +41,7 @@ class Request EXTRA_STORAGES = %i[aggs suggest].freeze # An array of storage names that are changing the returned hist collection in any way. WHERE_STORAGES = %i[ - query filter post_filter none types min_score rescore indices_boost + query filter post_filter none min_score rescore indices_boost ].freeze delegate :hits, :wrappers, :objects, :records, :documents, @@ -60,11 +60,11 @@ class Request # Chewy::Search::Request.new(:places) # # => ["places"]}> # Chewy::Search::Request.new(PlacesIndex) - # # => ["places"], :type=>["city", "country"]}> + # # => ["places"]}> # Chewy::Search::Request.new(PlacesIndex::City) - # # => ["places"], :type=>["city"]}> + # # => ["places"]}> # Chewy::Search::Request.new(UsersIndex, PlacesIndex::City) - # # => ["users", "places"], :type=>["city", "user"]}> + # # => ["users", "places"]}> # @param indexes_or_types [Array] indices and types in any combinations def initialize(*indices_or_types) indices = indices_or_types.reject do |klass| @@ -75,8 +75,10 @@ def initialize(*indices_or_types) klass.is_a?(Class) && klass < Chewy::Type end + indices += types.map(&:index) + parameters.modify!(:indices) do - replace!(indices: indices, types: types) + replace!(indices: indices) end end @@ -305,34 +307,18 @@ def inspect end end - # @!method indices(*values) - # Modifies `index` request parameter. Updates the storage on every call. - # Added passed indexes to the parameter list. - # - # @example - # UsersIndex.indices(CitiesIndex).indices(:another) - # # => ["another", "cities", "users"], :type=>["city", "user"]}> - # @see Chewy::Search::Parameters::Indices - # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html - # @param values [Array] index names - # @return [Chewy::Search::Request] + # Modifies `index` request parameter. Updates the storage on every call. + # Added passed indexes to the parameter list. # - # @!method types(*values) - # Modifies `type` request parameter. Updates the storage on every call. - # Constrains types passed on the request initialization or adds them - # to the list depending on circumstances. - # - # @example - # UsersIndex.types(CitiesIndex::City).types(:unexistent) - # # => ["cities", "users"], :type=>["city", "user"]}> - # @see Chewy::Search::Parameters::Indices - # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html - # @param values [Array] type names - # @return [Chewy::Search::Request] - %i[indices types].each do |name| - define_method name do |value, *values| - modify(:indices) { update!(name => [value, *values]) } - end + # @example + # UsersIndex.indices(CitiesIndex).indices(:another) + # # => ["another", "cities", "users"]}> + # @see Chewy::Search::Parameters::Indices + # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html + # @param values [Array] index names + # @return [Chewy::Search::Request] + def indices(value, *values) + modify(:indices) { update!(indices: [value, *values]) } end # @overload reorder(*values) @@ -990,7 +976,6 @@ def reset def perform(additional = {}) request_body = render.merge(additional) - request_body[:rest_total_hits_as_int] = true if Runtime.version >= '7.0.0' ActiveSupport::Notifications.instrument 'search_query.chewy', notification_payload(request: request_body) do begin @@ -1003,9 +988,8 @@ def perform(additional = {}) def notification_payload(additional) { - indexes: _indices, types: _types, - index: _indices.one? ? _indices.first : _indices, - type: _types.one? ? _types.first : _types + indexes: _indices, + index: _indices.one? ? _indices.first : _indices }.merge(additional) end @@ -1013,10 +997,6 @@ def _indices parameters[:indices].indices end - def _types - parameters[:indices].types - end - def raw_limit_value parameters[:limit].value end diff --git a/lib/chewy/search/response.rb b/lib/chewy/search/response.rb index 6ee733f04..9169d0367 100644 --- a/lib/chewy/search/response.rb +++ b/lib/chewy/search/response.rb @@ -23,7 +23,7 @@ def hits # # @return [Integer] def total - @total ||= hits_root['total'] || 0 + @total ||= hits_root.fetch('total', {}).fetch('value', 0) end # Response `max_score` field. diff --git a/lib/chewy/search/scrolling.rb b/lib/chewy/search/scrolling.rb index f3baf4534..b71f21d75 100644 --- a/lib/chewy/search/scrolling.rb +++ b/lib/chewy/search/scrolling.rb @@ -28,7 +28,7 @@ def scroll_batches(batch_size: Request::DEFAULT_BATCH_SIZE, scroll: Request::DEF return enum_for(:scroll_batches, batch_size: batch_size, scroll: scroll) unless block_given? result = perform(size: batch_size, scroll: scroll) - total = [raw_limit_value, result.fetch('hits', {}).fetch('total', 0)].compact.min + total = [raw_limit_value, result.fetch('hits', {}).fetch('total', {}).fetch('value', 0)].compact.min last_batch_size = total % batch_size fetched = 0 scroll_id = nil diff --git a/lib/chewy/stash.rb b/lib/chewy/stash.rb index fc3b5fc24..6d461d116 100644 --- a/lib/chewy/stash.rb +++ b/lib/chewy/stash.rb @@ -46,11 +46,8 @@ def self.for(*something) types = something.flat_map { |s| Chewy.derive_types(s) } return none if something.present? && types.blank? scope = all - types.group_by(&:index).each do |index, index_types| - scope = scope.or( - filter(term: {index_name: index.derivable_name}) - .filter(terms: {type_name: index_types.map(&:type_name)}) - ) + types.map(&:index).uniq.each do |index| + scope = scope.or(filter(term: {index_name: index.derivable_name})) end scope end diff --git a/lib/chewy/type/import/bulk_request.rb b/lib/chewy/type/import/bulk_request.rb index b87423b78..fb94e4aa5 100644 --- a/lib/chewy/type/import/bulk_request.rb +++ b/lib/chewy/type/import/bulk_request.rb @@ -47,8 +47,7 @@ def perform(body) def request_base @request_base ||= { - index: @type.index_name(suffix: @suffix), - type: @type.type_name + index: @type.index_name(suffix: @suffix) }.merge!(@bulk_options) end diff --git a/lib/chewy/type/import/journal_builder.rb b/lib/chewy/type/import/journal_builder.rb index 8402aa7f4..510c96a93 100644 --- a/lib/chewy/type/import/journal_builder.rb +++ b/lib/chewy/type/import/journal_builder.rb @@ -17,8 +17,7 @@ def bulk_body ].compact ).bulk_body.each do |item| item.values.first.merge!( - _index: Chewy::Stash::Journal.index_name, - _type: Chewy::Stash::Journal::Journal.type_name + _index: Chewy::Stash::Journal.index_name ) end end diff --git a/lib/chewy/type/import/routine.rb b/lib/chewy/type/import/routine.rb index f24ece155..777838356 100644 --- a/lib/chewy/type/import/routine.rb +++ b/lib/chewy/type/import/routine.rb @@ -69,8 +69,8 @@ def create_indexes! @type.index.create!(**@bulk_options.slice(:suffix)) unless @type.index.exists? end - # The main process method. Converts passed objects to thr bulk request body, - # appends journal entires, performs this request and handles errors performing + # The main process method. Converts passed objects to the bulk request body, + # appends journal entries, performs this request and handles errors performing # failover procedures if applicable. # # @param index [Array] any acceptable objects for indexing diff --git a/lib/chewy/type/mapping.rb b/lib/chewy/type/mapping.rb index f02355510..5efd5ffec 100644 --- a/lib/chewy/type/mapping.rb +++ b/lib/chewy/type/mapping.rb @@ -183,7 +183,7 @@ def template(*args) # Returns compiled mappings hash for current type # def mappings_hash - root.mappings_hash[type_name.to_sym].present? ? root.mappings_hash : {} + root.mappings_hash end # Check whether the type has outdated_sync_field defined with a simple value. diff --git a/lib/chewy/type/syncer.rb b/lib/chewy/type/syncer.rb index db4e7794a..01121b50b 100644 --- a/lib/chewy/type/syncer.rb +++ b/lib/chewy/type/syncer.rb @@ -205,12 +205,9 @@ def outdated_sync_field_type return @outdated_sync_field_type if instance_variable_defined?(:@outdated_sync_field_type) return unless @type.outdated_sync_field - args = {index: @type.index_name, type: @type.type_name} - args[:include_type_name] = true if Runtime.version >= '6.7.0' - mappings = @type.client.indices.get_mapping(**args).values.first.fetch('mappings', {}) + mappings = @type.client.indices.get_mapping(index: @type.index_name).values.first.fetch('mappings', {}) @outdated_sync_field_type = mappings - .fetch(@type.type_name, {}) .fetch('properties', {}) .fetch(@type.outdated_sync_field.to_s, {})['type'] rescue Elasticsearch::Transport::Transport::Errors::NotFound diff --git a/lib/chewy/version.rb b/lib/chewy/version.rb index 30bb3335a..1fd9c9304 100644 --- a/lib/chewy/version.rb +++ b/lib/chewy/version.rb @@ -1,3 +1,3 @@ module Chewy - VERSION = '7.0.0'.freeze + VERSION = '7.1.0'.freeze end diff --git a/migration_guide.md b/migration_guide.md index 7f1cf48f0..0ffb535a5 100644 --- a/migration_guide.md +++ b/migration_guide.md @@ -10,10 +10,13 @@ In order to upgrade Chewy 6/Elasticsearch 6 to Chewy 7/Elasticsearch 7 in the mo * Upgrade to the latest 6.x stable releases, namely Chewy 6.0, Elasticsearch 6.8 * Study carefully [Breaking changes in 7.0](https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking-changes-7.0.htmll), make sure your application conforms. -* Run your test suite on Chewy 7 / Elasticsearch 7 -* Run manual tests on Chewy 7 / Elasticsearch 7 -* Upgrade to Chewy 7 +* Run your test suite on Chewy 7.0 / Elasticsearch 7 +* Run manual tests on Chewy 7.0 / Elasticsearch 7 +* Upgrade to Chewy 7.0 * Perform a [rolling upgrade](https://www.elastic.co/guide/en/elasticsearch/reference//rolling-upgrades.html) of Elasticsearch +* Run your test suite on Chewy 7.1 / Elasticsearch 7 +* Run manual tests on Chewy 7.1 / Elasticsearch 7 +* Upgrade to Chewy 7.1 ## Chewy 5/Elasticsearch 5 to Chewy 6/Elasticsearch 6 diff --git a/spec/chewy/fields/base_spec.rb b/spec/chewy/fields/base_spec.rb index d62e9e840..8240c0e33 100644 --- a/spec/chewy/fields/base_spec.rb +++ b/spec/chewy/fields/base_spec.rb @@ -143,7 +143,7 @@ end specify do - expect(EventsIndex::Event.mappings_hash).to eq(event: { + expect(EventsIndex::Event.mappings_hash).to eq( properties: { id: {type: 'integer'}, category: { @@ -160,7 +160,7 @@ } } } - }) + ) end end @@ -296,7 +296,7 @@ end specify do - expect(EventsIndex::Event.mappings_hash).to eq(event: { + expect(EventsIndex::Event.mappings_hash).to eq( properties: { id: {type: 'integer'}, name: { @@ -307,7 +307,7 @@ }, category: {type: 'object'} } - }) + ) end specify do diff --git a/spec/chewy/fields/root_spec.rb b/spec/chewy/fields/root_spec.rb index 63e456a60..6bf1dbeca 100644 --- a/spec/chewy/fields/root_spec.rb +++ b/spec/chewy/fields/root_spec.rb @@ -13,7 +13,7 @@ field.dynamic_template template_42: {mapping: {}, match: ''} field.dynamic_template(/hello\..*/) - expect(field.mappings_hash).to eq(product: {dynamic_templates: [ + expect(field.mappings_hash).to eq(dynamic_templates: [ {template_1: {mapping: {type: 'keyword'}, match: 'hello'}}, {template_2: {mapping: {}, match_mapping_type: 'integer', match: 'hello*'}}, {template_3: {mapping: {}, path_match: 'hello.*'}}, @@ -21,7 +21,7 @@ {template_5: {mapping: {}, match: 'hello.*', match_pattern: 'regexp'}}, {template_42: {mapping: {}, match: ''}}, {template_7: {mapping: {}, path_match: 'hello\..*', match_pattern: 'regexp'}} - ]}) + ]) end context do @@ -33,10 +33,10 @@ specify do field.dynamic_template 'hello', type: 'keyword' - expect(field.mappings_hash).to eq(product: {dynamic_templates: [ + expect(field.mappings_hash).to eq(dynamic_templates: [ {template_42: {mapping: {}, match: ''}}, {template_1: {mapping: {type: 'keyword'}, match: 'hello'}} - ]}) + ]) end end end diff --git a/spec/chewy/index/specification_spec.rb b/spec/chewy/index/specification_spec.rb index 744a1c172..07f997edf 100644 --- a/spec/chewy/index/specification_spec.rb +++ b/spec/chewy/index/specification_spec.rb @@ -56,12 +56,12 @@ specify do expect { specification1.lock! }.to change { Chewy::Stash::Specification.all.hits }.from([]).to([{ '_index' => 'chewy_specifications', - '_type' => 'specification', + '_type' => '_doc', '_id' => 'places', '_score' => 1.0, '_source' => {'specification' => Base64.encode64({ 'settings' => {'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}}, - 'mappings' => {'city' => {'properties' => {'founded_on' => {'type' => 'date'}}}} + 'mappings' => {'properties' => {'founded_on' => {'type' => 'date'}}} }.to_json)} }]) end @@ -72,21 +72,21 @@ specify do expect { specification5.lock! }.to change { Chewy::Stash::Specification.all.hits }.to([{ '_index' => 'chewy_specifications', - '_type' => 'specification', + '_type' => '_doc', '_id' => 'places', '_score' => 1.0, '_source' => {'specification' => Base64.encode64({ 'settings' => {'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}}, - 'mappings' => {'city' => {'properties' => {'founded_on' => {'type' => 'date'}}}} + 'mappings' => {'properties' => {'founded_on' => {'type' => 'date'}}} }.to_json)} }, { '_index' => 'chewy_specifications', - '_type' => 'specification', + '_type' => '_doc', '_id' => 'namespace/cities', '_score' => 1.0, '_source' => {'specification' => Base64.encode64({ 'settings' => {'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}}, - 'mappings' => {'city' => {'properties' => {'population' => {'type' => 'integer'}}}} + 'mappings' => {'properties' => {'population' => {'type' => 'integer'}}} }.to_json)} }]) end @@ -97,14 +97,14 @@ specify do expect { specification1.lock! }.to change { specification1.locked }.from({}).to( 'settings' => {'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}}, - 'mappings' => {'city' => {'properties' => {'founded_on' => {'type' => 'date'}}}} + 'mappings' => {'properties' => {'founded_on' => {'type' => 'date'}}} ) end specify do expect { specification5.lock! }.to change { specification5.locked }.from({}).to( 'settings' => {'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}}, - 'mappings' => {'city' => {'properties' => {'population' => {'type' => 'integer'}}}} + 'mappings' => {'properties' => {'population' => {'type' => 'integer'}}} ) end @@ -114,20 +114,20 @@ specify do expect { specification2.lock! }.to change { specification2.locked }.from( 'settings' => {'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}}, - 'mappings' => {'city' => {'properties' => {'founded_on' => {'type' => 'date'}}}} + 'mappings' => {'properties' => {'founded_on' => {'type' => 'date'}}} ).to( 'settings' => {'analyzer' => {}, 'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}}, - 'mappings' => {'city' => {'properties' => {'founded_on' => {'type' => 'date'}}}} + 'mappings' => {'properties' => {'founded_on' => {'type' => 'date'}}} ) end specify do expect { specification3.lock! }.to change { specification3.locked }.from( 'settings' => {'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}}, - 'mappings' => {'city' => {'properties' => {'founded_on' => {'type' => 'date'}}}} + 'mappings' => {'properties' => {'founded_on' => {'type' => 'date'}}} ).to( 'settings' => {'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}}, - 'mappings' => {'city' => {'properties' => {'founded_on' => {'type' => 'date'}, 'population' => {'type' => 'integer'}}}} + 'mappings' => {'properties' => {'founded_on' => {'type' => 'date'}, 'population' => {'type' => 'integer'}}} ) end end @@ -136,7 +136,7 @@ describe '#current' do specify do expect(specification2.current).to eq( - 'mappings' => {'city' => {'properties' => {'founded_on' => {'type' => 'date'}}}}, + 'mappings' => {'properties' => {'founded_on' => {'type' => 'date'}}}, 'settings' => {'analyzer' => {}, 'index' => {'number_of_shards' => 1, 'number_of_replicas' => 0}} ) end diff --git a/spec/chewy/index_spec.rb b/spec/chewy/index_spec.rb index b1ddc5e9e..4bcb57b93 100644 --- a/spec/chewy/index_spec.rb +++ b/spec/chewy/index_spec.rb @@ -143,8 +143,6 @@ class DummyCityIndex2 < Chewy::Index describe '.types' do specify { expect(DummiesIndex.types).to eq(DummiesIndex.type_hash.values) } - specify { expect(DummiesIndex.types(:dummy)).to be_a Chewy::Search::Request } - specify { expect(DummiesIndex.types(:user)).to be_a Chewy::Search::Request } end describe '.settings' do @@ -233,7 +231,7 @@ def self.by_id; end define_type :document do field :date, type: 'date' end - end.mappings_hash).to eq(mappings: {document: {properties: {date: {type: 'date'}}}}) + end.mappings_hash).to eq(mappings: {properties: {date: {type: 'date'}}}) end end diff --git a/spec/chewy/journal_spec.rb b/spec/chewy/journal_spec.rb index 491574878..abae9fa6b 100644 --- a/spec/chewy/journal_spec.rb +++ b/spec/chewy/journal_spec.rb @@ -137,7 +137,7 @@ def timestamp(time) expect(journal_entries.size).to eq 4 # simulate lost data - Chewy.client.delete(index: "#{Chewy.settings[:prefix]}_cities", type: 'city', id: 1, refresh: true) + Chewy.client.delete(index: "#{Chewy.settings[:prefix]}_cities", id: 1, refresh: true) expect(cities_index.count).to eq 1 described_class.new.apply(time) @@ -192,8 +192,8 @@ def timestamp(time) Array.new(2) { |i| Country.create!(id: i + 1) } # simulate lost data - Chewy.client.delete(index: 'cities', type: 'city', id: 1, refresh: true) - Chewy.client.delete(index: 'countries', type: 'country', id: 1, refresh: true) + Chewy.client.delete(index: 'cities', id: 1, refresh: true) + Chewy.client.delete(index: 'countries', id: 1, refresh: true) expect(CitiesIndex.all.to_a.length).to eq 1 expect(CountriesIndex.all.to_a.length).to eq 1 @@ -203,7 +203,7 @@ def timestamp(time) expect(CountriesIndex.all.to_a.length).to eq 1 # Replay on both - Chewy.client.delete(index: 'cities', type: 'city', id: 1, refresh: true) + Chewy.client.delete(index: 'cities', id: 1, refresh: true) expect(CitiesIndex.all.to_a.length).to eq 1 expect(described_class.new(CitiesIndex, CountriesIndex).apply(time)).to eq(4) expect(CitiesIndex.all.to_a.length).to eq 2 diff --git a/spec/chewy/runtime_spec.rb b/spec/chewy/runtime_spec.rb index bc21bcacc..edc85231b 100644 --- a/spec/chewy/runtime_spec.rb +++ b/spec/chewy/runtime_spec.rb @@ -3,7 +3,7 @@ describe Chewy::Runtime do describe '.version' do specify { expect(described_class.version).to be_a(described_class::Version) } - specify { expect(described_class.version).to be >= '6.8' } + specify { expect(described_class.version).to be >= '7.0' } specify { expect(described_class.version).to be < '8.0' } end end diff --git a/spec/chewy/search/loader_spec.rb b/spec/chewy/search/loader_spec.rb index c054c79aa..deb618285 100644 --- a/spec/chewy/search/loader_spec.rb +++ b/spec/chewy/search/loader_spec.rb @@ -37,7 +37,6 @@ specify { expect(subject.derive_type('cities', 'city')).to eq(CitiesIndex::City) } specify { expect(subject.derive_type('cities_suffix', 'city')).to eq(CitiesIndex::City) } - specify { expect { subject.derive_type('cities', 'place') }.to raise_error(Chewy::UnderivableType) } specify { expect { subject.derive_type('whatever', 'city') }.to raise_error(Chewy::UnderivableType) } specify { expect { subject.derive_type('citiessuffix', 'city') }.to raise_error(Chewy::UnderivableType) } @@ -54,21 +53,6 @@ specify { expect(subject.load(hits)).to eq([*cities, *countries]) } - context do - let(:options) { {only: 'city'} } - specify { expect(subject.load(hits)).to eq([*cities, nil, nil]) } - end - - context do - let(:options) { {except: 'city'} } - specify { expect(subject.load(hits)).to eq([nil, nil, *countries]) } - end - - context do - let(:options) { {except: %w[city country]} } - specify { expect(subject.load(hits)).to eq([nil, nil, nil, nil]) } - end - context 'scopes', :active_record do context do let(:options) { {scope: -> { where('rating > 2') }} } diff --git a/spec/chewy/search/parameters/indices_spec.rb b/spec/chewy/search/parameters/indices_spec.rb index 97b54cd43..649e7d3a5 100644 --- a/spec/chewy/search/parameters/indices_spec.rb +++ b/spec/chewy/search/parameters/indices_spec.rb @@ -9,30 +9,32 @@ stub_index(:second) do define_type :three end + + stub_index(:third) end - subject { described_class.new(indices: FirstIndex, types: SecondIndex::Three) } + subject { described_class.new(indices: [FirstIndex, SecondIndex]) } describe '#initialize' do - specify { expect(described_class.new.value).to eq(indices: [], types: []) } - specify { expect(described_class.new(nil).value).to eq(indices: [], types: []) } - specify { expect(described_class.new(foo: :whatever).value).to eq(indices: [], types: []) } - specify { expect(subject.value).to eq(indices: [FirstIndex], types: [SecondIndex::Three]) } + specify { expect(described_class.new.value).to eq(indices: []) } + specify { expect(described_class.new(nil).value).to eq(indices: []) } + specify { expect(described_class.new(foo: :whatever).value).to eq(indices: []) } + specify { expect(subject.value).to eq(indices: [FirstIndex, SecondIndex]) } end describe '#replace!' do specify do expect { subject.replace!(nil) } .to change { subject.value } - .from(indices: [FirstIndex], types: [SecondIndex::Three]) - .to(indices: [], types: []) + .from(indices: [FirstIndex, SecondIndex]) + .to(indices: []) end specify do - expect { subject.replace!(indices: SecondIndex, types: FirstIndex::One) } + expect { subject.replace!(indices: SecondIndex) } .to change { subject.value } - .from(indices: [FirstIndex], types: [SecondIndex::Three]) - .to(indices: [SecondIndex], types: [FirstIndex::One]) + .from(indices: [FirstIndex, SecondIndex]) + .to(indices: [SecondIndex]) end end @@ -43,10 +45,10 @@ end specify do - expect { subject.update!(indices: SecondIndex, types: [FirstIndex::One, SecondIndex::Three]) } + expect { subject.update!(indices: ThirdIndex) } .to change { subject.value } - .from(indices: [FirstIndex], types: [SecondIndex::Three]) - .to(indices: [FirstIndex, SecondIndex], types: [SecondIndex::Three, FirstIndex::One]) + .from(indices: [FirstIndex, SecondIndex]) + .to(indices: [FirstIndex, SecondIndex, ThirdIndex]) end end @@ -57,10 +59,8 @@ end specify do - expect { subject.merge!(described_class.new(indices: SecondIndex, types: [FirstIndex::One, SecondIndex::Three])) } - .to change { subject.value } - .from(indices: [FirstIndex], types: [SecondIndex::Three]) - .to(indices: [FirstIndex, SecondIndex], types: [SecondIndex::Three, FirstIndex::One]) + expect { subject.merge!(described_class.new(indices: SecondIndex)) } + .not_to change { subject.value } end end @@ -69,7 +69,7 @@ specify do expect(described_class.new( indices: FirstIndex - ).render).to eq(index: %w[first], type: %w[one]) + ).render).to eq(index: %w[first]) end specify do expect(described_class.new( @@ -78,113 +78,28 @@ end specify do expect(described_class.new( - types: FirstIndex::One - ).render).to eq(index: %w[first], type: %w[one]) - end - specify do - expect(described_class.new( - types: :whatever - ).render).to eq({}) - end - specify do - expect(described_class.new( - indices: FirstIndex, types: SecondIndex::Three - ).render).to eq(index: %w[first second], type: %w[one three]) - end - specify do - expect(described_class.new( - indices: FirstIndex, types: :one - ).render).to eq(index: %w[first], type: %w[one]) - end - specify do - expect(described_class.new( - indices: FirstIndex, types: :whatever - ).render).to eq(index: %w[first], type: %w[one]) - end - specify do - expect(described_class.new( - indices: FirstIndex, types: %i[one whatever] - ).render).to eq(index: %w[first], type: %w[one]) - end - specify do - expect(described_class.new( - indices: :whatever, types: SecondIndex::Three - ).render).to eq(index: %w[second whatever], type: %w[three]) - end - specify do - expect(described_class.new( - indices: :whatever, types: [SecondIndex::Three, :whatever] - ).render).to eq(index: %w[second whatever], type: %w[three whatever]) - end - specify do - expect(described_class.new( - indices: [FirstIndex, :whatever], types: FirstIndex::One - ).render).to eq(index: %w[first whatever], type: %w[one]) - end - specify do - expect(described_class.new( - indices: FirstIndex, types: [FirstIndex::One, :whatever] - ).render).to eq(index: %w[first], type: %w[one]) - end - specify do - expect(described_class.new( - indices: FirstIndex, types: [SecondIndex::Three, :whatever] - ).render).to eq(index: %w[first second], type: %w[one three]) - end - specify do - expect(described_class.new( - indices: [FirstIndex, :whatever], types: [FirstIndex::One, :whatever] - ).render).to eq(index: %w[first whatever], type: %w[one whatever]) - end - specify do - expect(described_class.new( - indices: [FirstIndex, :whatever], types: [SecondIndex::Three, FirstIndex::One] - ).render).to eq(index: %w[first second whatever], type: %w[one three]) + indices: [FirstIndex, :whatever] + ).render).to eq(index: %w[first whatever]) end end describe '#==' do specify { expect(described_class.new).to eq(described_class.new) } specify do - expect(described_class.new(indices: SecondIndex, types: [SecondIndex::Three, :whatever])) - .to eq(described_class.new(indices: SecondIndex, types: :whatever)) - end - specify do - expect(described_class.new(indices: :first, types: %w[one])) + expect(described_class.new(indices: :first)) .to eq(described_class.new(indices: FirstIndex)) end specify do - expect(described_class.new(indices: FirstIndex, types: SecondIndex::Three)) - .not_to eq(described_class.new(indices: FirstIndex)) + expect(described_class.new(indices: FirstIndex)) + .to eq(described_class.new(indices: FirstIndex)) end end describe '#indices' do specify do expect(described_class.new( - indices: [FirstIndex, :whatever], - types: [SecondIndex::Three, :whatever] - ).indices).to contain_exactly(FirstIndex, SecondIndex) - end - end - - describe '#types' do - specify do - expect(described_class.new( - indices: [FirstIndex, :whatever], - types: [SecondIndex::Three, :whatever] - ).types).to contain_exactly( - FirstIndex::One, SecondIndex::Three - ) - end - - specify do - expect(described_class.new( - indices: [FirstIndex, :whatever], - types: [FirstIndex::One, SecondIndex::Three, :whatever] - ).types).to contain_exactly( - FirstIndex::One, SecondIndex::Three - ) + indices: [FirstIndex, :whatever] + ).indices).to contain_exactly(FirstIndex) end end end diff --git a/spec/chewy/search/parameters/types_spec.rb b/spec/chewy/search/parameters/types_spec.rb deleted file mode 100644 index 3bf197169..000000000 --- a/spec/chewy/search/parameters/types_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'chewy/search/parameters/string_array_storage_examples' - -describe Chewy::Search::Parameters::Types do - it_behaves_like :string_array_storage, nil -end diff --git a/spec/chewy/search/request_spec.rb b/spec/chewy/search/request_spec.rb index e75b4b941..d84a6239d 100644 --- a/spec/chewy/search/request_spec.rb +++ b/spec/chewy/search/request_spec.rb @@ -46,7 +46,6 @@ expect(subject.render) .to match( index: %w[products], - type: array_including(%w[product]), body: {} ) end @@ -55,11 +54,11 @@ describe '#inspect' do specify do expect(described_class.new(ProductsIndex).inspect) - .to eq('["products"], :type=>["product"], :body=>{}}>') + .to eq('["products"], :body=>{}}>') end specify do expect(ProductsIndex.limit(10).inspect) - .to eq('["products"], :type=>["product"], :body=>{:size=>10}}>') + .to eq('["products"], :body=>{:size=>10}}>') end end @@ -231,14 +230,6 @@ specify { expect { subject.indices(:cities) }.not_to change { subject.render } } end - describe '#types' do - specify { expect(subject.types(:product).render[:type]).to contain_exactly('product') } - specify { expect(subject.types(%i[product city]).types(nil).render[:type]).to match_array(%w[product]) } - specify { expect(subject.types(:product).types(:product, :city, :something).render[:type]).to match_array(%w[product]) } - specify { expect(subject.types(nil).render[:body]).to be_blank } - specify { expect { subject.types(:product) }.not_to change { subject.render } } - end - describe '#indices_boost' do specify { expect(subject.indices_boost(foo: 1.2).render[:body]).to include(indices_boost: [{'foo' => 1.2}]) } specify { expect(subject.indices_boost(foo: 1.2).indices_boost(moo: 1.3).render[:body]).to include(indices_boost: [{'foo' => 1.2}, {'moo' => 1.3}]) } @@ -420,14 +411,10 @@ outer_payload = payload end subject.query(match: {name: 'name3'}).to_a - request = {index: ['products'], type: %w[product], body: {query: {match: {name: 'name3'}}}} - request[:rest_total_hits_as_int] = true if Chewy::Runtime.version >= '7.0.0' expect(outer_payload).to eq( index: ProductsIndex, indexes: [ProductsIndex], - request: request, - type: ProductsIndex::Product, - types: [ProductsIndex::Product] + request: {index: ['products'], body: {query: {match: {name: 'name3'}}}} ) end end @@ -592,12 +579,12 @@ specify { expect(subject.limit(5).pluck(:_id, :age)).to eq([['1', 10], ['2', 20], ['3', 30], ['4', 40], ['5', 50]]) } specify { expect(subject.limit(5).source(:name).pluck(:id, :age)).to eq([[1, 10], [2, 20], [3, 30], [4, 40], [5, 50]]) } specify do - expect(subject.limit(5).pluck(:_index, :_type, :name)).to eq([ - %w[products product Name1], - %w[products product Name2], - %w[products product Name3], - %w[products product Name4], - %w[products product Name5] + expect(subject.limit(5).pluck(:_index, :name)).to eq([ + %w[products Name1], + %w[products Name2], + %w[products Name3], + %w[products Name4], + %w[products Name5] ]) end @@ -644,9 +631,7 @@ expect(outer_payload).to eq( index: ProductsIndex, indexes: [ProductsIndex], - request: {index: ['products'], type: %w[product], body: {query: {match: {name: 'name3'}}}, refresh: true}, - type: ProductsIndex::Product, - types: [ProductsIndex::Product] + request: {index: ['products'], body: {query: {match: {name: 'name3'}}}, refresh: true} ) end @@ -659,9 +644,7 @@ expect(outer_payload).to eq( index: ProductsIndex, indexes: [ProductsIndex], - request: {index: ['products'], type: %w[product], body: {query: {match: {name: 'name3'}}}, refresh: false}, - type: ProductsIndex::Product, - types: [ProductsIndex::Product] + request: {index: ['products'], body: {query: {match: {name: 'name3'}}}, refresh: false} ) end end diff --git a/spec/chewy/search/scrolling_spec.rb b/spec/chewy/search/scrolling_spec.rb index 8e21f4e6c..aa0b64174 100644 --- a/spec/chewy/search/scrolling_spec.rb +++ b/spec/chewy/search/scrolling_spec.rb @@ -119,22 +119,16 @@ outer_payload << payload end request.scroll_batches(batch_size: 3).to_a - request = {index: %w[cities countries], type: %w[city country], body: {sort: ['rating']}, size: 3, scroll: '1m'} - request[:rest_total_hits_as_int] = true if Chewy::Runtime.version >= '7.0.0' expect(outer_payload).to match_array([ hash_including( index: [CitiesIndex, CountriesIndex], indexes: [CitiesIndex, CountriesIndex], - request: request, - type: [CitiesIndex::City, CountriesIndex::Country], - types: [CitiesIndex::City, CountriesIndex::Country] + request: {index: %w[cities countries], body: {sort: ['rating']}, size: 3, scroll: '1m'} ), hash_including( index: [CitiesIndex, CountriesIndex], indexes: [CitiesIndex, CountriesIndex], - request: {scroll: '1m', scroll_id: an_instance_of(String)}, - type: [CitiesIndex::City, CountriesIndex::Country], - types: [CitiesIndex::City, CountriesIndex::Country] + request: {scroll: '1m', scroll_id: an_instance_of(String)} ) ]) end diff --git a/spec/chewy/search_spec.rb b/spec/chewy/search_spec.rb index 0b7468230..f8e52faf6 100644 --- a/spec/chewy/search_spec.rb +++ b/spec/chewy/search_spec.rb @@ -37,12 +37,12 @@ end specify do - expect(ProductsIndex.client).to receive(:search).with(hash_including(index: ['products'], type: %w[product])) + expect(ProductsIndex.client).to receive(:search).with(hash_including(index: ['products'])) ProductsIndex.search_string('hello') end specify do - expect(ProductsIndex.client).to receive(:search).with(hash_including(index: ['products'], type: %w[product])) + expect(ProductsIndex.client).to receive(:search).with(hash_including(index: ['products'])) product.search_string('hello') end end diff --git a/spec/chewy/type/import/bulk_request_spec.rb b/spec/chewy/type/import/bulk_request_spec.rb index febfb7839..3b62fd8b8 100644 --- a/spec/chewy/type/import/bulk_request_spec.rb +++ b/spec/chewy/type/import/bulk_request_spec.rb @@ -32,7 +32,6 @@ specify do expect(Chewy.client).to receive(:bulk).with( index: 'places', - type: 'city', body: [{index: {id: 42, data: {name: 'Name'}}}] ) subject.perform([{index: {id: 42, data: {name: 'Name'}}}]) @@ -44,7 +43,6 @@ specify do expect(Chewy.client).to receive(:bulk).with( index: 'places_suffix', - type: 'city', body: [{index: {id: 42, data: {name: 'Name'}}}] ) subject.perform([{index: {id: 42, data: {name: 'Name'}}}]) @@ -57,7 +55,6 @@ specify do expect(Chewy.client).to receive(:bulk).with( index: 'places', - type: 'city', body: "{\"index\":{\"id\":42}}\n{\"name\":\"#{'Name' * 10}\"}\n{\"index\":{\"id\":43}}\n{\"name\":\"#{'Shame' * 10}\"}\n" ) subject.perform([ @@ -69,17 +66,14 @@ specify do expect(Chewy.client).to receive(:bulk).with( index: 'places', - type: 'city', body: "{\"index\":{\"id\":42}}\n{\"name\":\"#{'Name' * 30}\"}\n" ) expect(Chewy.client).to receive(:bulk).with( index: 'places', - type: 'city', body: "{\"index\":{\"id\":43}}\n{\"name\":\"#{'Shame' * 100}\"}\n" ) expect(Chewy.client).to receive(:bulk).with( index: 'places', - type: 'city', body: "{\"index\":{\"id\":44}}\n{\"name\":\"#{'Blame' * 30}\"}\n" ) subject.perform([ diff --git a/spec/chewy/type/import/journal_builder_spec.rb b/spec/chewy/type/import/journal_builder_spec.rb index dcc7ea54f..25b36f48c 100644 --- a/spec/chewy/type/import/journal_builder_spec.rb +++ b/spec/chewy/type/import/journal_builder_spec.rb @@ -29,7 +29,6 @@ expect(subject.bulk_body).to eq([{ index: { _index: 'chewy_journal', - _type: 'journal', data: { 'index_name' => 'namespace/cities', 'type_name' => 'city', @@ -48,7 +47,6 @@ expect(subject.bulk_body).to eq([{ index: { _index: 'chewy_journal', - _type: 'journal', data: { 'index_name' => 'namespace/cities', 'type_name' => 'city', @@ -69,7 +67,6 @@ expect(subject.bulk_body).to eq([{ index: { _index: 'chewy_journal', - _type: 'journal', data: { 'index_name' => 'namespace/countries', 'type_name' => 'country', @@ -81,7 +78,6 @@ }, { index: { _index: 'chewy_journal', - _type: 'journal', data: { 'index_name' => 'namespace/countries', 'type_name' => 'country', diff --git a/spec/chewy/type/import_spec.rb b/spec/chewy/type/import_spec.rb index 833e671a8..ad3f77f47 100644 --- a/spec/chewy/type/import_spec.rb +++ b/spec/chewy/type/import_spec.rb @@ -366,8 +366,8 @@ def subscribe_notification # Full match doesn't work here. expect(payload[:errors][:update].keys).to match([ - hash_including('type' => 'document_missing_exception', 'reason' => '[city][1]: document missing'), - hash_including('type' => 'document_missing_exception', 'reason' => '[city][3]: document missing') + hash_including('type' => 'document_missing_exception', 'reason' => '[_doc][1]: document missing'), + hash_including('type' => 'document_missing_exception', 'reason' => '[_doc][3]: document missing') ]) expect(payload[:errors][:update].values).to eq([['1'], ['3']]) expect(imported_cities).to match_array([ diff --git a/spec/chewy/type/mapping_spec.rb b/spec/chewy/type/mapping_spec.rb index f1cdb7d5b..a6ed5a633 100644 --- a/spec/chewy/type/mapping_spec.rb +++ b/spec/chewy/type/mapping_spec.rb @@ -59,7 +59,7 @@ Chewy.default_root_options = previous_options end - specify { expect(product.mappings_hash[:product]).to include(_all: {enabled: false}) } + specify { expect(product.mappings_hash).to include(_all: {enabled: false}) } end end @@ -90,12 +90,11 @@ before do stub_index(:products) do define_type :product do - root _parent: 'project', other_option: 'nothing' do + root other_option: 'nothing' do field :name do field :last_name # will be redefined in the following root flock end end - root _parent: 'something_else' root other_option: 'option_value' do field :identifier field :name, type: 'integer' @@ -105,47 +104,16 @@ end specify do - expect(product.mappings_hash).to eq(product: { + expect(product.mappings_hash).to eq( properties: { name: {type: 'integer'}, identifier: {type: Chewy.default_field_type} }, - other_option: 'option_value', - _parent: {type: 'something_else'} - }) + other_option: 'option_value' + ) end end end - - context 'parent-child relationship' do - context do - before do - stub_index(:products) do - define_type :product do - root _parent: 'project', parent_id: -> { project_id } do - field :name, 'surname' - end - end - end - end - - specify { expect(product.mappings_hash[:product][:_parent]).to eq(type: 'project') } - end - - context do - before do - stub_index(:products) do - define_type :product do - root parent: {'type' => 'project'}, parent_id: -> { project_id } do - field :name, 'surname' - end - end - end - end - - specify { expect(product.mappings_hash[:product][:_parent]).to eq('type' => 'project') } - end - end end describe '.supports_outdated_sync?' do