Class: Elasticity::IndexConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/elasticity/index_config.rb

Defined Under Namespace

Classes: SubclassError

Constant Summary collapse

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"
VERSION_FOR_SUBCLASS_ERROR =
"7.0.0"
ATTRS =
[
  :index_base_name, :document_type, :mapping, :strategy, :subclasses,
  :settings, :use_new_timestamp_format, :include_type_name_on_create
].freeze
VALIDATABLE_ATTRS =
[:index_base_name, :document_type, :strategy].freeze
DEPRECATED_ATTRS =
[:use_new_timestamp_format, :include_type_name_on_create].freeze

Instance Method Summary collapse

Constructor Details

#initialize(elasticity_config, defaults = {}) {|_self| ... } ⇒ IndexConfig

Returns a new instance of IndexConfig.

Yields:

  • (_self)

Yield Parameters:



20
21
22
23
24
25
26
27
28
29
# File 'lib/elasticity/index_config.rb', line 20

def initialize(elasticity_config, defaults = {})
  defaults.each do |k,v|
    instance_variable_set("@#{k}",v)
  end
  @elasticity_config = elasticity_config
  yield(self)
  subclasses_warning_or_exception
  warn_deprecated_config
  validate!
end

Instance Method Details

#clientObject



37
38
39
# File 'lib/elasticity/index_config.rb', line 37

def client
  @elasticity_config.client
end

#definitionObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/elasticity/index_config.rb', line 41

def definition
  return @definition if defined?(@definition)

  @definition = {
    settings: merge_settings,
    mappings: @mapping.nil? ? {} : @mapping.deep_stringify_keys
  }
  subclasses.each do |doc_type, subclass|
    @definition[:mappings][doc_type] = subclass.constantize.mapping
  end if subclasses.present?
  @definition
end

#document_typesObject



54
55
56
# File 'lib/elasticity/index_config.rb', line 54

def document_types
  @document_types ||= definition[:mappings].collect { |doc_type, mapping| doc_type }
end

#fq_index_base_nameObject



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/elasticity/index_config.rb', line 58

def fq_index_base_name
  return @fq_index_base_name if defined?(@fq_index_base_name)

  if namespace = @elasticity_config.namespace
    @fq_index_base_name = "#{namespace}_#{@index_base_name}"
  else
    @fq_index_base_name = @index_base_name
  end

  @fq_index_base_name
end

#segment(name) ⇒ Object



31
32
33
34
35
# File 'lib/elasticity/index_config.rb', line 31

def segment(name)
  new_config = self.dup
  new_config.index_base_name = "#{index_base_name}_#{name.underscore}"
  new_config
end

#strategyObject



70
71
72
# File 'lib/elasticity/index_config.rb', line 70

def strategy
  @strategy ||= Strategies::AliasIndex
end