diff --git a/.circleci/config.yml b/.circleci/config.yml index 3b27311bb..03f9a6a7f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -108,7 +108,7 @@ jobs: rspec-ruby-26-activerecord52: docker: - image: circleci/ruby:2.6 - - image: docker.elastic.co/elasticsearch/elasticsearch:5.6.7 + - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1 environment: <<: *es-env working_directory: ~/repo @@ -120,7 +120,7 @@ jobs: rspec-ruby-26-activerecord60: docker: - image: circleci/ruby:2.6 - - image: docker.elastic.co/elasticsearch/elasticsearch:5.6.7 + - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1 environment: <<: *es-env working_directory: ~/repo @@ -132,7 +132,7 @@ jobs: rspec-ruby-26-activerecord61: docker: - image: circleci/ruby:2.6 - - image: docker.elastic.co/elasticsearch/elasticsearch:5.6.7 + - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1 environment: <<: *es-env working_directory: ~/repo @@ -145,7 +145,7 @@ jobs: docker: - image: circleci/ruby:2.6 - image: circleci/mongo:4.2.5 - - image: docker.elastic.co/elasticsearch/elasticsearch:5.6.7 + - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1 environment: <<: *es-env working_directory: ~/repo @@ -157,7 +157,7 @@ jobs: rspec-ruby-27-activerecord52: docker: - image: circleci/ruby:2.7 - - image: docker.elastic.co/elasticsearch/elasticsearch:5.6.7 + - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1 environment: <<: *es-env working_directory: ~/repo @@ -169,7 +169,7 @@ jobs: rspec-ruby-27-activerecord60: docker: - image: circleci/ruby:2.7 - - image: docker.elastic.co/elasticsearch/elasticsearch:5.6.7 + - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1 environment: <<: *es-env working_directory: ~/repo @@ -181,7 +181,7 @@ jobs: rspec-ruby-27-activerecord61: docker: - image: circleci/ruby:2.7 - - image: docker.elastic.co/elasticsearch/elasticsearch:5.6.7 + - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1 environment: <<: *es-env working_directory: ~/repo @@ -194,7 +194,7 @@ jobs: docker: - image: circleci/ruby:2.7 - image: circleci/mongo:4.2.5 - - image: docker.elastic.co/elasticsearch/elasticsearch:5.6.7 + - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1 environment: <<: *es-env working_directory: ~/repo @@ -206,7 +206,7 @@ jobs: rspec-ruby-30-activerecord61: docker: - image: circleci/ruby:3.0 - - image: docker.elastic.co/elasticsearch/elasticsearch:5.6.7 + - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1 environment: <<: *es-env working_directory: ~/repo diff --git a/CHANGELOG.md b/CHANGELOG.md index ee725cf46..7c4b0324f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,13 +4,21 @@ ### New Features +### Changes + +### Bugs Fixed + +## 7.0.0 (2021-02-22) + +### New Features + + * [#763](https://github.com/toptal/chewy/pull/763): Added support for Elasticsearch 7 ([@rabotyaga][]) + ### Changes * [#757](https://github.com/toptal/chewy/pull/757): **(Breaking)** Fix `Chewy::Index.index` & `Chewy::Index.aliases` to correctly report indexes and aliases ([@mpeychich][], [@dalthon][]) * [#761](https://github.com/toptal/chewy/pull/761): Avoid fetching scope data to check if it is blank ([@dalthon][]) -### Bugs Fixed - ## 6.0.0 (2021-02-11) ### Changes diff --git a/README.md b/README.md index b15485bf2..3a31309ac 100644 --- a/README.md +++ b/README.md @@ -95,13 +95,15 @@ Chewy is compatible with MRI 2.5-3.0¹. > ¹ Ruby 3 is only supported with Rails 6.1 -### Elasticsearch +### Elasticsearch compatibility matrix -Chewy 5 is compatible with Elasticsearch 5. +| Chewy version | Elasticsearch version | +| ------------- | ---------------------------------- | +| 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 | -Chewy 6 is compatible with Elasticsearch 6. See [Migration guide](migration_guide.md). - -Future versions of Chewy will support Elasticsearch 7. +See [Migration guide](migration_guide.md). ## Usage diff --git a/lib/chewy/search/request.rb b/lib/chewy/search/request.rb index 2a44c17a3..77f19d6cc 100644 --- a/lib/chewy/search/request.rb +++ b/lib/chewy/search/request.rb @@ -990,6 +990,7 @@ 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 diff --git a/lib/chewy/stash.rb b/lib/chewy/stash.rb index 4fae155a5..fc3b5fc24 100644 --- a/lib/chewy/stash.rb +++ b/lib/chewy/stash.rb @@ -24,7 +24,7 @@ class Journal < Chewy::Index # @param since_time [Time, DateTime] a timestamp from which we load a journal # @param only [Chewy::Index, Array] journal entries related to these indices will be loaded only def self.entries(since_time, only: []) - self.for(only).filter(range: {created_at: {gt: since_time}}) + self.for(only).filter(range: {created_at: {gt: since_time}}).filter.minimum_should_match(1) end # Cleans up all the journal entries until the specified time. If nothing is diff --git a/lib/chewy/version.rb b/lib/chewy/version.rb index 861e14c6f..30bb3335a 100644 --- a/lib/chewy/version.rb +++ b/lib/chewy/version.rb @@ -1,3 +1,3 @@ module Chewy - VERSION = '6.0.0'.freeze + VERSION = '7.0.0'.freeze end diff --git a/migration_guide.md b/migration_guide.md index 0ead18efc..7f1cf48f0 100644 --- a/migration_guide.md +++ b/migration_guide.md @@ -4,6 +4,17 @@ This document outlines the steps you need to take when migrating between major v Chewy and Elasticsearch. For simplicity's sake the guide will assume that you're using Chewy alongside a matching Elasticsearch version. +## Chewy 6/Elasticsearch 6 to Chewy 7/Elasticsearch 7 + +In order to upgrade Chewy 6/Elasticsearch 6 to Chewy 7/Elasticsearch 7 in the most seamless manner you have to: + +* 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 +* Perform a [rolling upgrade](https://www.elastic.co/guide/en/elasticsearch/reference//rolling-upgrades.html) of Elasticsearch + ## Chewy 5/Elasticsearch 5 to Chewy 6/Elasticsearch 6 In order to upgrade Chewy 5/Elasticsearch 5 to Chewy 6/Elasticsearch 6 in the most seamless manner you have to: @@ -17,7 +28,7 @@ In order to upgrade Chewy 5/Elasticsearch 5 to Chewy 6/Elasticsearch 6 in the mo * replace fields with `{ type: 'string', index: 'analyzed'}` by `{type: 'text'}` * `PathHierarchy` tokenizer' param `delimiter` now accepts only one argument, [others should be replaced by character filter ](https://discuss.elastic.co/t/multichar-delimiter-in-path-hierarchy-tokenizer/16203) * Make sure you don't use any other of the [deprecated Elasticsearch 5 features](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/breaking-changes-6.0.html) -* Run your test suite on Elasticsearch 6 -* Run manual tests on Elasticsearch 6 -* Perform a [rolling upgrade](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/rolling-upgrades.html) of Elasticsearch +* Run your test suite on Chewy 6 / Elasticsearch 6 +* Run manual tests on Chewy 6 / Elasticsearch 6 * Upgrade to Chewy 6 +* Perform a [rolling upgrade](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/rolling-upgrades.html) of Elasticsearch diff --git a/spec/chewy/runtime_spec.rb b/spec/chewy/runtime_spec.rb index 7126fd8fc..bc21bcacc 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 >= '5.6' } - specify { expect(described_class.version).to be < '7.0' } + specify { expect(described_class.version).to be >= '6.8' } + specify { expect(described_class.version).to be < '8.0' } end end diff --git a/spec/chewy/search/request_spec.rb b/spec/chewy/search/request_spec.rb index 17abd68ff..e75b4b941 100644 --- a/spec/chewy/search/request_spec.rb +++ b/spec/chewy/search/request_spec.rb @@ -420,10 +420,12 @@ 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: {index: ['products'], type: %w[product], body: {query: {match: {name: 'name3'}}}}, + request: request, type: ProductsIndex::Product, types: [ProductsIndex::Product] ) diff --git a/spec/chewy/search/scrolling_spec.rb b/spec/chewy/search/scrolling_spec.rb index 2ed049892..8e21f4e6c 100644 --- a/spec/chewy/search/scrolling_spec.rb +++ b/spec/chewy/search/scrolling_spec.rb @@ -119,12 +119,13 @@ 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: {index: %w[cities countries], type: %w[city country], body: {sort: ['rating']}, size: 3, scroll: '1m'}, + request: request, type: [CitiesIndex::City, CountriesIndex::Country], types: [CitiesIndex::City, CountriesIndex::Country] ),