lib/elasticity/index_mapper.rb in es-elasticity-0.14.1 vs lib/elasticity/index_mapper.rb in es-elasticity-1.0.0.jhumphreys

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + module Elasticity class IndexMapper def self.set_delegates(obj, to) obj.delegate( :document_type, @@ -82,11 +84,11 @@ @strategy.refresh end # Index the given document def index_document(id, document_hash) - @strategy.index_document(document_type, id, document_hash) + @strategy.index_document(id, document_hash) end # Searches the index using the parameters provided in the body hash, following the same # structure Elasticsearch expects. # Returns a DocumentSearch object. @@ -97,39 +99,38 @@ Search::DocumentProxy.new(search_obj, self.method(:map_hit)) end # Fetches one specific document from the index by ID. def get(id) - doc = @strategy.get_document(document_type, id) - @document_klass.new(doc["_source"].merge(_id: doc['_id'])) if doc.present? + doc = @strategy.get_document(id) + @document_klass.new(doc["_source"].merge(_id: doc["_id"])) if doc.present? end # Removes one specific document from the index. def delete(id) - @strategy.delete_document(document_type, id) + @strategy.delete_document(id) end # Removes entries based on a search def delete_by_search(search) - @strategy.delete_by_query(document_type, search.body) + @strategy.delete_by_query(search.body) end # Bulk index the provided documents def bulk_index(documents) @strategy.bulk do |b| documents.each do |doc| - b.index(document_type, doc._id, doc.to_document) + b.index(doc._id, doc.to_document) end end end # Bulk update the specicied attribute of the provided documents def bulk_update(documents) @strategy.bulk do |b| documents.each do |doc| b.update( - document_type, doc[:_id], { doc: { doc[:attr_name] => doc[:attr_value] } } ) end end @@ -137,11 +138,11 @@ # Bulk delete documents matching provided ids def bulk_delete(ids) @strategy.bulk do |b| ids.each do |id| - b.delete(document_type, id) + b.delete(id) end end end # Creates a instance of a document from a ElasticSearch hit data. @@ -154,10 +155,10 @@ highlighted = nil if hit["highlight"] highlighted_attrs = hit["highlight"].each_with_object({}) do |(name, v), attrs| - name = name.gsub(/\..*\z/, '') + name = name.gsub(/\..*\z/, "") attrs[name] ||= v end highlighted = @document_klass.new(attrs.merge(highlighted_attrs))