Is it possible to delete all the documents in index ?

Elamathi R 20 Reputation points
2024-03-28T04:22:44.0066667+00:00

I'm attempting to remove all documents from the index using a for loop. Although the output shows "delete new document succeeded: True," it doesn't reflect in the search index or the document count on the Azure AI Search portal dashboard.

Is it possible to delete all the documents in index ?

Is using a for loop to delete all documents from the index the correct approach? If not, please suggest an alternative method to delete all documents in index.

for doc_id in vector_store:
    print(doc_id)

    result = search_client.delete_documents(documents=[{"id": "doc_id"}])

    print("Delete new document succeeded: {}".format(result[0].succeeded))
Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
708 questions
{count} votes

Accepted answer
  1. Vahid Ghafarpour 17,875 Reputation points
    2024-03-28T04:52:00.3266667+00:00

    Thanks for posting your question in the Microsoft Q&A forum.

    To delete all documents in an Azure Cognitive Search index, I would use the delete_index method provided by the SDK.

    https://learn.microsoft.com/en-us/python/api/azure-search-documents/azure.search.documents.indexes.searchindexclient?view=azure-python#azure-search-documents-indexes-searchindexclient-delete-index

    Deletes a search index and all the documents it contains. The model must be provided instead of the name to use the access conditions.

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful **

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. VenkateshDodda-MSFT 18,281 Reputation points Microsoft Employee
    2024-03-29T05:00:09.3633333+00:00

    @Elamathi R Thanks for reaching out to Microsoft Q&A, apologize for any inconvenience caused on this.

    I understand that you want to delete all the documents under the index then you can use this rest api .

    If you are deleting the files/documents from vector index and you notice the space of the index is not show accurately then you can refer to my answer posted in the similar thread here.
    Hope this helps let me know if you have any further questions on this.

    1 person found this answer helpful.