Method: ElasticRecord::Callbacks#elastic_search_value

Defined in:
lib/elastic_record/callbacks.rb

#elastic_search_value(field, mapping) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/elastic_record/callbacks.rb', line 53

def elastic_search_value(field, mapping)
  value = try field
  return if value.nil?

  value = case mapping[:type]
    when :object
      value.as_search
    when :nested
      value.map(&:as_search)
    else
      value
    end

  if value.present? || value == false
    value
  end

rescue
  raise "Field not found for #{field.inspect}"
end