Skip to content

Commit

Permalink
Drop support for Elasticsearch 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Rabotyaga committed Mar 2, 2021
1 parent f8ff5d3 commit 96b12e5
Show file tree
Hide file tree
Showing 38 changed files with 149 additions and 449 deletions.
26 changes: 0 additions & 26 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ gem 'guard-rspec'

gem 'redcarpet'
gem 'yard'

gem 'pry'
gem 'rexml' if RUBY_VERSION >= '3.0.0'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
3 changes: 1 addition & 2 deletions lib/chewy/fields/root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 4 additions & 15 deletions lib/chewy/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions lib/chewy/index/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions lib/chewy/index/aliases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 2 additions & 12 deletions lib/chewy/search/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ module Search
# @see Chewy::Search::Scrolling#scroll_objects
class Loader
# @param indexes [Array<Chewy::Index>] list of indexes to lookup types
# @param only [Array<String, Symbol>] list of selected type names to load
# @param except [Array<String, Symbol>] 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

Expand All @@ -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

Expand All @@ -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))
Expand All @@ -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
69 changes: 12 additions & 57 deletions lib/chewy/search/parameters/indices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<Chewy::Index, Chewy::Type, String, Symbol>}] any acceptable storage value
# @return [{Symbol => Array<Chewy::Index, Chewy::Type, String, Symbol>}] updated value
# @param other_value [{Symbol => Array<Chewy::Index, String, Symbol>}] any acceptable storage value
# @return [{Symbol => Array<Chewy::Index, String, Symbol>}] 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<String>}] 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<Chewy::Index>] 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<Chewy::Type>] a list of types classes
def types
type_classes | (index_classes - type_classes.map(&:index)).flat_map(&:types)
index_classes
end

private
Expand All @@ -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
Expand All @@ -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
Expand Down
20 changes: 0 additions & 20 deletions lib/chewy/search/parameters/types.rb

This file was deleted.

Loading

0 comments on commit 96b12e5

Please sign in to comment.