Class: Elasticity::IndexConfig
- Inherits:
-
Object
- Object
- Elasticity::IndexConfig
- 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
- #client ⇒ Object
- #definition ⇒ Object
- #document_types ⇒ Object
- #fq_index_base_name ⇒ Object
-
#initialize(elasticity_config, defaults = {}) {|_self| ... } ⇒ IndexConfig
constructor
A new instance of IndexConfig.
- #segment(name) ⇒ Object
- #strategy ⇒ Object
Constructor Details
#initialize(elasticity_config, defaults = {}) {|_self| ... } ⇒ IndexConfig
Returns a new instance of IndexConfig.
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
#client ⇒ Object
37 38 39 |
# File 'lib/elasticity/index_config.rb', line 37 def client @elasticity_config.client end |
#definition ⇒ Object
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_types ⇒ Object
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_name ⇒ Object
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 |
#strategy ⇒ Object
70 71 72 |
# File 'lib/elasticity/index_config.rb', line 70 def strategy @strategy ||= Strategies::AliasIndex end |