Document ID not found error while updating a document, even though we have that document ID present in the ES

So, what I am trying to do is get a document from ES cluster, make some changes into the document and then update this document back into the elastic search cluster.
I am using elasticsearch's python client and .update to update the document back to es cluster. Now the problem is sometimes this .update gives us DocumentID not found error, but that document id is present there for sure, because we are getting the document with the same document ID and then trying to update it.
I tried to figure out the issue and somehow I think this related to refresh API.
Can someone provide some suggestions or how to go about this.

Hi ,
Can you provide the code you use.