When i search for document after index a document. It returns empty but it returns document with sleep of 2 seconds between creating and fetching

Thank you for the answer. Is there anyway to ensure the indexing a document is successful before start searching it?