update_document

in elasticsearch-model/lib/elasticsearch/model/indexing.rb [413:432]


        def update_document(options={})
          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!(options))
            end
          else
            index_document(options)
          end
        end