Azure / Azure/azure-sdk-for-python

Need some wait when use SearchClient for actual count

Abierto
#40,644 2 comentarios 0 reacciones 1 asignado Reclamado por @xiangyan99 Ver en GitHub
Client customer-reported feature-request Search
Lenguaje dominante
Python
Estrellas
5.6k
Forks
3.4k
Merge medio
2 d 2 h
PR fusionados (30 d)
213

Descripción

**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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.