Azure / Azure/azure-sdk-for-python
Need some wait when use SearchClient for actual count
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 3.4k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 193
Description
**Is your feature request related to a problem? Please describe.**
When we delete or upload the documents, the actual count is some delay.
So we need to wait like this
> time.sleep(2)

```
## import
import time
import asyncio
from azure.core.credentials import AzureKeyCredential
from azure.search.documents import SearchClient
search_endpoint: str = "https://.search.windows.net"
search_api_key: str = ""
index_name: str = ""
from azure.core.credentials import AzureKeyCredential
# Create a client
credential = AzureKeyCredential(search_api_key)
client = SearchClient(endpoint=search_endpoint,
index_name=index_name,
credential=credential)
count = 10000 # count 10000
async def delete():
for i in range(0, count):
result = client.delete_documents(documents=[{"id": str(i)}])
## print("Delete new document succeeded: {}".format(result[0].succeeded))
client.get_document_count()
## print("Current Document count: {}".format(client.get_document_count()))
async def main():
await delete()
print("*** Deleted")
if __name__ == "__main__":
asyncio.run(main())
elapsed = 0
while True:
remaining = client.get_document_count()
print("Current document count: {}".format(remaining))
if remaining == 0:
break
time.sleep(2)
elapsed += 2
if elapsed >= 600:
raise TimeoutError(f"abort")
print("*** completed")
```
**Describe the solution you'd like**
It wanted to be explained in documents at least.
**Describe alternatives you've considered**
Implement as above.
**Additional context**
N/A
Contributor guide
Assessment
This issue has not been assessed yet.