Method: Elasticsearch::Model::Indexing::InstanceMethods#update_document
- Defined in:
- lib/elasticsearch/model/indexing.rb
permalink #update_document(options = {}) ⇒ Hash
Tries to gather the changed attributes of a model instance (via [ActiveModel::Dirty](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.
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
# File 'lib/elasticsearch/model/indexing.rb', line 414 def update_document(={}) if attributes_in_database = self.instance_variable_get(:@__changed_model_attributes).presence attributes = if respond_to?(:as_indexed_json) self.as_indexed_json.select { |k,v| attributes_in_database.keys.map(&:to_s).include? k.to_s } else attributes_in_database end unless attributes.empty? request = { index: index_name, id: self.id, body: { doc: attributes } } client.update(request.merge!()) end else index_document() end end |