Sha256: 773486ed02ebe881bac3f48d4f725e255930f5a1b3247f94f16179c2cb8b0ac2

Contents?: true

Size: 1.02 KB

Versions: 15

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

# The es 7.6 deprecate the mapping definition under the type level. That's why we have option
# to define mappings under both Type and Index. If the index mapping is defined. All the Type
# mapping will be ignored.
# Source: https://www.elastic.co/guide/en/elasticsearch/reference/7.6/removal-of-types.html
module Esse
  class Index
    module ClassMethods
      # This method is only used to define mapping
      def mappings(hash = {}, &block)
        @mapping = Esse::IndexMapping.new(body: hash, paths: template_dirs, globals: -> { cluster.mappings })
        return unless block

        @mapping.define_singleton_method(:to_h, &block)
      end

      def mappings_hash
        hash = mapping.body
        { Esse::MAPPING_ROOT_KEY => (hash.key?(Esse::MAPPING_ROOT_KEY) ? hash[Esse::MAPPING_ROOT_KEY] : hash) }
      end

      private

      def mapping
        @mapping ||= Esse::IndexMapping.new(paths: template_dirs, globals: -> { cluster.mappings })
      end
    end

    extend ClassMethods
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
esse-0.4.0.rc4 lib/esse/index/mappings.rb
esse-0.4.0.rc3 lib/esse/index/mappings.rb
esse-0.4.0.rc2 lib/esse/index/mappings.rb
esse-0.4.0.rc1 lib/esse/index/mappings.rb
esse-0.3.5 lib/esse/index/mappings.rb
esse-0.3.4 lib/esse/index/mappings.rb
esse-0.3.3 lib/esse/index/mappings.rb
esse-0.3.2 lib/esse/index/mappings.rb
esse-0.3.1 lib/esse/index/mappings.rb
esse-0.3.0 lib/esse/index/mappings.rb
esse-0.2.6 lib/esse/index/mappings.rb
esse-0.2.5 lib/esse/index/mappings.rb
esse-0.2.4 lib/esse/index/mappings.rb
esse-0.2.3 lib/esse/index/mappings.rb
esse-0.2.2 lib/esse/index/mappings.rb