lib/searchkick/index.rb in searchkick-0.7.5 vs lib/searchkick/index.rb in searchkick-0.7.6
- old
+ new
@@ -42,11 +42,11 @@
def import(records)
records.group_by{|r| document_type(r) }.each do |type, batch|
client.bulk(
index: name,
type: type,
- body: batch.map{|r| data = search_data(r); {index: {_id: search_id(r), data: data}} }
+ body: batch.map{|r| {index: {_id: search_id(r), data: search_data(r)}} }
)
end
end
def retrieve(record)
@@ -56,11 +56,15 @@
id: record.id
)["_source"]
end
def klass_document_type(klass)
- klass.model_name.to_s.underscore
+ if klass.respond_to?(:document_type)
+ klass.document_type
+ else
+ klass.model_name.to_s.underscore
+ end
end
protected
def client
@@ -75,16 +79,16 @@
record.id.is_a?(Numeric) ? record.id : record.id.to_s
end
def search_data(record)
source = record.search_data
+ options = record.class.searchkick_options
# stringify fields
- source = source.inject({}){|memo,(k,v)| memo[k.to_s] = v; memo}.except("id", "_id")
+ # remove _id since search_id is used instead
+ source = source.inject({}){|memo,(k,v)| memo[k.to_s] = v; memo}.except("_id")
- options = record.class.searchkick_options
-
# conversions
conversions_field = options[:conversions]
if conversions_field and source[conversions_field]
source[conversions_field] = source[conversions_field].map{|k, v| {query: k, count: v} }
end
@@ -104,11 +108,9 @@
end
end
end
cast_big_decimal(source)
-
- # p search_data
source.as_json
end
# change all BigDecimal values to floats due to