module AxleAttributes class Definition module Indexed def index options[:index] end ANALYZERS = [:snowball, :proper_noun, :simple] def analyzer_mapping {type: 'string', analyzer: index} if ANALYZERS.include?(index) end INDEXES_BY_TYPE = { array: {type: "string", index: "not_analyzed", doc_values: true}, boolean: {type: "boolean", doc_values: true}, float: {type: "double", doc_values: true}, integer: {type: "long", doc_values: true}, json: {type: "boolean"}, string: {type: 'string', index_analyzer: 'keyword', search_analyzer: 'standard'}, text: {type: 'string', index_analyzer: 'keyword', search_analyzer: 'standard'}, time: {type: "date", format: "dateOptionalTime", doc_values: true}, date: {type: "date", format: "date", doc_values: true} } def index_mapping return unless index if mapping = analyzer_mapping multi_field_index(name, mapping) elsif index == true INDEXES_BY_TYPE[type] || (raise "unknown index type #{type.inspect} for #{name}") elsif index.is_a?(Hash) index end end def multi_field_index(field, analyzer_mapping) {type: "multi_field", fields: {field => {type: "string", index: "not_analyzed", doc_values: true}, analyzed: analyzer_mapping}} end end end end