Skip to content

Need some wait when use SearchClient for actual count #40644

Open
@nobuko-yamada

Description

@nobuko-yamada

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

## import 

import time
import asyncio
from azure.core.credentials import AzureKeyCredential
from azure.search.documents import SearchClient

search_endpoint: str = "https://<search>.search.windows.net"
search_api_key: str = "<apikey>"
index_name: str = "<indexname>"

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

Metadata

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.Searchcustomer-reportedIssues that are reported by GitHub users external to the Azure organization.feature-requestThis issue requires a new behavior in the product in order be resolved.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions