@wrap_exceptions<EOL><INDENT>def update(self, document_id, update_spec, namespace, timestamp):<DEDENT>
index, doc_type = self._index_and_mapping(namespace)<EOL>with self.lock:<EOL><INDENT>document = self.BulkBuffer.get_from_sources(index,<EOL>doc_type,<EOL>u(document_id))<EOL><DEDENT>if document:<EOL><INDENT>updated = self.apply_update(document, update_spec)<EOL>updated['<STR_LIT>'] = document_id<EOL>self.upsert(updated, namespace, timestamp)<EOL><DEDENT>else:<EOL><INDENT>updated = {"<STR_LIT>": document_id}<EOL>self.upsert(updated, namespace, timestamp, update_spec)<EOL><DEDENT>return updated<EOL>
Apply updates given in update_spec to the document whose id
        matches that of doc.