Class: Elastic::Fields::Value

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/elastic/fields/value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_name, _options) ⇒ Value

Returns a new instance of Value.



14
15
16
17
18
# File 'lib/elastic/fields/value.rb', line 14

def initialize(_name, _options)
  @name = _name.to_s
  @options = _options.symbolize_keys
  @mapping_inference = true
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/elastic/fields/value.rb', line 5

def name
  @name
end

Instance Method Details

#disable_mapping_inferenceObject



42
43
44
# File 'lib/elastic/fields/value.rb', line 42

def disable_mapping_inference
  @mapping_inference = false
end

#freezeObject



46
47
48
49
50
# File 'lib/elastic/fields/value.rb', line 46

def freeze
  @name.freeze
  @options.freeze
  load_transform_and_datatype
end

#get_field(_name) ⇒ Object



29
30
31
# File 'lib/elastic/fields/value.rb', line 29

def get_field(_name)
  nil
end

#merge!(_options) ⇒ Object



24
25
26
27
# File 'lib/elastic/fields/value.rb', line 24

def merge!(_options)
  return if _options.nil?
  @options.merge! _options.symbolize_keys
end

#needs_inference?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/elastic/fields/value.rb', line 38

def needs_inference?
  mapping_inference_enabled? && !@options.key?(:type)
end

#nested?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/elastic/fields/value.rb', line 20

def nested?
  false
end

#prepare_value_for_index(_value) ⇒ Object



57
58
59
60
# File 'lib/elastic/fields/value.rb', line 57

def prepare_value_for_index(_value)
  _value = @transform.apply _value if @transform
  @datatype.prepare_for_index _value
end

#prepare_value_for_query(_value) ⇒ Object



52
53
54
55
# File 'lib/elastic/fields/value.rb', line 52

def prepare_value_for_query(_value)
  _value = @transform.apply _value if @transform
  @datatype.prepare_for_query _value
end

#validateObject



33
34
35
36
# File 'lib/elastic/fields/value.rb', line 33

def validate
  return "explicit field type for #{@name} required" unless @options.key? :type
  nil
end