diff --git a/CHANGELOG.md b/CHANGELOG.md index b04deb977..3ec446687 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ ### Changes +* [#1028](https://github.com/toptal/chewy/pull/1028): Remove the obsolete `_type` field from mock response helpers (`Chewy::Minitest::Helpers`, `Chewy::Rspec::Helpers`), `EVERFIELDS`, and `Chewy::Index::Wrapper` accessors. Elasticsearch removed `_type` from search responses in 8.0 (ES 7 already returned only the placeholder `_doc`), so these references no longer matched real responses. Also removes the long-obsolete `_parent` entry from `EVERFIELDS`. ([@mattmenefee][]) + ## 8.2.1 (2026-06-01) ### New Features diff --git a/README.md b/README.md index 8b7f9aabc..9f352cfea 100644 --- a/README.md +++ b/README.md @@ -218,7 +218,6 @@ end }, "_data":{ "_index":"users", - "_type":"_doc", "_id":"1", "_score":0.9808291, "_source":{ diff --git a/lib/chewy/index/wrapper.rb b/lib/chewy/index/wrapper.rb index e69a316ea..014ac74ea 100644 --- a/lib/chewy/index/wrapper.rb +++ b/lib/chewy/index/wrapper.rb @@ -39,7 +39,7 @@ def ==(other) end end - %w[_id _type _index].each do |name| + %w[_id _index].each do |name| define_method name do _data[name] end diff --git a/lib/chewy/minitest/helpers.rb b/lib/chewy/minitest/helpers.rb index 0254c8f97..47b103f37 100644 --- a/lib/chewy/minitest/helpers.rb +++ b/lib/chewy/minitest/helpers.rb @@ -96,7 +96,6 @@ def mock_elasticsearch_response_sources(index, hits, &block) 'hits' => hits.each_with_index.map do |hit, i| { '_index' => index.index_name, - '_type' => '_doc', '_id' => hit[:id] || (i + 1).to_s, '_score' => 3.14, '_source' => hit diff --git a/lib/chewy/rspec/helpers.rb b/lib/chewy/rspec/helpers.rb index e3efb459a..af5cccc4d 100644 --- a/lib/chewy/rspec/helpers.rb +++ b/lib/chewy/rspec/helpers.rb @@ -39,7 +39,6 @@ def mock_elasticsearch_response_sources(index, hits) 'hits' => hits.each_with_index.map do |hit, i| { '_index' => index.index_name, - '_type' => '_doc', '_id' => (i + 1).to_s, '_score' => 3.14, '_source' => hit diff --git a/lib/chewy/search/request.rb b/lib/chewy/search/request.rb index 2bbabe276..9f44059c1 100644 --- a/lib/chewy/search/request.rb +++ b/lib/chewy/search/request.rb @@ -18,7 +18,7 @@ class Request include Scoping include Scrolling UNDEFINED = Class.new.freeze - EVERFIELDS = %w[_index _type _id _parent _routing].freeze + EVERFIELDS = %w[_index _id _routing].freeze DELEGATED_METHODS = %i[ query filter post_filter knn order reorder docvalue_fields track_scores track_total_hits request_cache explain version profile @@ -952,7 +952,7 @@ def find(*ids) # Returns and array of values for specified fields. # Uses `source` to restrict the list of returned fields. - # Fields `_id`, `_type`, `_routing` and `_index` are also supported. + # Fields `_id`, `_routing` and `_index` are also supported. # # @overload pluck(field) # If single field is passed - it returns and array of values. diff --git a/migration_guide.md b/migration_guide.md index 4ea6ab433..5f53359e0 100644 --- a/migration_guide.md +++ b/migration_guide.md @@ -25,6 +25,9 @@ In order to upgrade Chewy 7/Elasticsearch 7 to Chewy 8/Elasticsearch 8 in the mo * In test suites, consider switching to targeted index deletion instead of `Chewy.massacre` * Configure Elasticsearch 8 security: * ES 8 enables security features by default. Ensure your Chewy configuration includes proper authentication (username/password or API key) and SSL/TLS settings as needed. +* Update test assertions for mock responses: + * If you use `mock_elasticsearch_response_sources` (in `Chewy::Minitest::Helpers` or `Chewy::Rspec::Helpers`), remove any assertions expecting `'_type' => '_doc'` in the mock hits it returns. The `_type` field has been removed from these helpers to match actual ES response format (ES 8 removed `_type` from search responses; ES 7 still returned the placeholder `'_doc'`). + * If you use `mock_elasticsearch_response` with a hand-crafted raw response hash, ensure your raw response does not include `'_type'` for consistency with ES 8+ responses. * Run your test suite on Chewy 8 / Elasticsearch 8 * Run manual tests on Chewy 8 / Elasticsearch 8 * Upgrade to Chewy 8 diff --git a/spec/chewy/minitest/helpers_spec.rb b/spec/chewy/minitest/helpers_spec.rb index d700edccd..e83d24a18 100644 --- a/spec/chewy/minitest/helpers_spec.rb +++ b/spec/chewy/minitest/helpers_spec.rb @@ -31,7 +31,6 @@ def assert_equal(expected, actual, message) [ { '_index' => 'dummies', - '_type' => '_doc', '_id' => '2', '_score' => 3.14, '_source' => source diff --git a/spec/chewy/rspec/helpers_spec.rb b/spec/chewy/rspec/helpers_spec.rb index 1d2e6cfd3..c005061e6 100644 --- a/spec/chewy/rspec/helpers_spec.rb +++ b/spec/chewy/rspec/helpers_spec.rb @@ -13,7 +13,6 @@ [ { '_index' => 'cities', - '_type' => '_doc', '_id' => '1', '_score' => 3.14, '_source' => source diff --git a/spec/chewy/search/response_spec.rb b/spec/chewy/search/response_spec.rb index 7fd91720a..7601b4f73 100644 --- a/spec/chewy/search/response_spec.rb +++ b/spec/chewy/search/response_spec.rb @@ -138,7 +138,6 @@ let(:raw_response) do {'hits' => {'hits' => [ {'_index' => 'cities', - '_type' => 'city', '_id' => '1', '_score' => 1.3, '_source' => {'id' => 2, 'rating' => 0}} @@ -155,7 +154,6 @@ let(:raw_response) do {'hits' => {'hits' => [ {'_index' => 'countries', - '_type' => 'country', '_id' => '2', '_score' => 1.2, '_explanation' => {foo: 'bar'}}