Module: ActiveEs::Schema::Definition

Extended by:
ActiveSupport::Concern
Included in:
ActiveEs::Schema
Defined in:
lib/active_es/schema/definition.rb

Constant Summary collapse

FieldDetaTypes =
%w(
  text keyword
  long integer short byte
  double float half_float scaled_float
  date
  boolean
  binary
  integer_range float_range long_range double_range date_range
)

Instance Method Summary collapse

Instance Method Details

#create_schemaObject



29
30
31
# File 'lib/active_es/schema/definition.rb', line 29

def create_schema
  client.indices.create index: index, body: mappings
end

#delete_schemaObject



33
34
35
# File 'lib/active_es/schema/definition.rb', line 33

def delete_schema
  client.indices.delete index: index
end

#property(field, **options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/active_es/schema/definition.rb', line 16

def property(field, **options)
  if options.values.all? { |key| FieldDetaTypes.exclude?(key) }
    raise ArgumentError('invalid field deta types')
  end

  unless defined? properties
    class_attribute :properties, default: {}
  end

  properties[field] = options
  attr_accessor field
end

#reset_schemaObject



37
38
39
40
# File 'lib/active_es/schema/definition.rb', line 37

def reset_schema
  delete_schema
  create_schema
end