<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def update_sources(self):
 """Update local sources based on response from Elasticsearch"""

        ES_documents = self.get_docs_sources_from_ES()

        for doc, update_spec, action_buffer_index, get_from_ES in self.doc_to_update:
            if get_from_ES:
                # Update source based on response from ES
                ES_doc = next(ES_documents)
                if ES_doc["found"]:
                    source = ES_doc["_source"]
                else:
                    # Document not found in elasticsearch,
                    # Seems like something went wrong during replication
                    LOG.error(
                        "mGET: Document id: %s has not been found "
                        "in Elasticsearch. Due to that "
                        "following update failed: %s",
                        doc["_id"],
                        update_spec,
                    )
                    self.reset_action(action_buffer_index)
                    continue
            else:
                # Get source stored locally before applying update
                # as it is up-to-date
                source = self.get_from_sources(doc["_index"], doc["_type"], doc["_id"])
                if not source:
                    LOG.error(
                        "mGET: Document id: %s has not been found "
                        "in local sources. Due to that following "
                        "update failed: %s",
                        doc["_id"],
                        update_spec,
                    )
                    self.reset_action(action_buffer_index)
                    continue

            updated = self.docman.apply_update(source, update_spec)

            # Remove _id field from source
            if "_id" in updated:
                del updated["_id"]

            # Everytime update locally stored sources to keep them up-to-date
            self.add_to_sources(doc, updated)

            self.action_buffer[action_buffer_index][
                "_source"
            ] = self.docman._formatter.format_document(updated)

        # Remove empty actions if there were errors
        self.action_buffer = [
            each_action for each_action in self.action_buffer if each_action
        ]