lib/elasticity/index_mapper.rb in es-elasticity-0.5.2 vs lib/elasticity/index_mapper.rb in es-elasticity-0.6.0
- old
+ new
@@ -30,10 +30,11 @@
@strategy = @index_config.strategy.new(@index_config.client, @index_config.fq_index_base_name, @index_config.document_type)
end
delegate(
:document_type,
+ :document_types,
:mapping,
:ref_index_name,
to: :@index_config
)
@@ -80,11 +81,11 @@
# Searches the index using the parameters provided in the body hash, following the same
# structure Elasticsearch expects.
# Returns a DocumentSearch object.
def search(body)
- search_obj = Search.build(@index_config.client, @strategy.search_index, document_type, body)
+ search_obj = Search.build(@index_config.client, @strategy.search_index, document_types, body)
Search::DocumentProxy.new(search_obj, self.method(:map_hit))
end
# Fetches one specific document from the index by ID.
def get(id)
@@ -150,10 +151,13 @@
attrs_set << name
end
highlighted = @document_klass.new(highlighted_attrs)
end
-
- @document_klass.new(attrs.merge(highlighted: highlighted))
+ if @document_klass.config.subclasses.present?
+ @document_klass.config.subclasses[hit["_type"].to_sym].constantize.new(attrs.merge(highlighted: highlighted))
+ else
+ @document_klass.new(attrs.merge(highlighted: highlighted))
+ end
end
end
end