lib/elasticity/index_config.rb in es-elasticity-0.11.5 vs lib/elasticity/index_config.rb in es-elasticity-0.12.0
- old
+ new
@@ -1,7 +1,15 @@
module Elasticity
class IndexConfig
+ class SubclassError < StandardError; end
+
+ SUBCLASSES_WARNING = "Indices created in Elasticsearch 6.0.0 or later may only contain a single mapping type. " +
+ "Therefore, doument-type based inheritance has been disabled by Elasticity"
+ SUBCLASSES_ERROR = "Mapping types have been completely removed in Elasticsearch 7.0.0. " +
+ "Therefore, doument-type based inheritance has been disabled by Elasticity"
+ VERSION_FOR_SUBCLASS_WARNING = "6.0.0".freeze
+ VERSION_FOR_SUBCLASS_ERROR = "7.0.0".freeze
ATTRS = [
:index_base_name, :document_type, :mapping, :strategy, :subclasses,
:settings
].freeze
VALIDATABLE_ATTRS = [:index_base_name, :document_type, :strategy].freeze
@@ -12,10 +20,11 @@
defaults.each do |k,v|
instance_variable_set("@#{k}",v)
end
@elasticity_config = elasticity_config
yield(self)
+ subclasses_warning_or_exception
validate!
end
def segment(name)
new_config = self.dup
@@ -66,8 +75,18 @@
end
end
def merge_settings
@elasticity_config.settings.merge(settings || {})
+ end
+
+ def subclasses_warning_or_exception
+ return if subclasses.nil? || subclasses.empty?
+ raise(SubclassError.new(SUBCLASSES_ERROR)) if es_version_meets_or_exceeds?(VERSION_FOR_SUBCLASS_ERROR)
+ warn(SUBCLASSES_WARNING) if es_version_meets_or_exceeds?(VERSION_FOR_SUBCLASS_WARNING)
+ end
+
+ def es_version_meets_or_exceeds?(test_version)
+ client.versions.any?{ |v| v >= test_version }
end
end
end