lib/elasticsearch/model/indexing.rb in elasticsearch-model-0.1.5 vs lib/elasticsearch/model/indexing.rb in elasticsearch-model-0.1.6
- old
+ new
@@ -315,10 +315,12 @@
# (via [ActiveModel::Dirty](http://api.rubyonrails.org/classes/ActiveModel/Dirty.html)),
# performing a _partial_ update of the document.
#
# When the changed attributes are not available, performs full re-index of the record.
#
+ # See the {#update_document_attributes} method for updating specific attributes directly.
+ #
# @param options [Hash] Optional arguments for passing to the client
#
# @example Update a document corresponding to the record
#
# @article = Article.first
@@ -348,9 +350,32 @@
body: { doc: attributes } }.merge(options)
)
else
index_document(options)
end
+ end
+
+ # Perform a _partial_ update of specific document attributes
+ # (without consideration for changed attributes as in {#update_document})
+ #
+ # @param attributes [Hash] Attributes to be updated
+ # @param options [Hash] Optional arguments for passing to the client
+ #
+ # @example Update the `title` attribute
+ #
+ # @article = Article.first
+ # @article.title = "New title"
+ # @article.__elasticsearch__.update_document_attributes title: "New title"
+ #
+ # @return [Hash] The response from Elasticsearch
+ #
+ def update_document_attributes(attributes, options={})
+ client.update(
+ { index: index_name,
+ type: document_type,
+ id: self.id,
+ body: { doc: attributes } }.merge(options)
+ )
end
end
end
end