Azure / Azure/azure-sdk-for-python

Need some wait when use SearchClient for actual count

Open
#40,644 2 comments 0 reactions 1 assignee Claimed by @xiangyan99 View on GitHub
Client customer-reported feature-request Search
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)

![Image](https://github.com/user-attachments/assets/fb22b79e-5eb1-486e-950e-9f8e97d5b5ba)

```
## 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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.