jsanchezs
jsanchezs

Reputation: 2070

Azure cognitive search index API delete by file name

I deleted a file from my Azure storage account tied to my cognitive search using the containers explorer, as the indexer stills find that file when it's searched in my webapp, I learned that I must delete the file using the index API due to it still exists there and indeed, when I look in Azure index shows this response:

{
  "@search.score": 7.9088755,
  "id": "aHR0cHM6Ly9kYXRhbWluaW5nc2EuYmxvYi5jb3JlLndpbmRvd3MubmV0L2RvY3VtZW50YWwvcGxhbl9wcmVtaXVtX3YxODZ2Mi5w****",
  "fileName": "deleted_file.pdf"
}

But when I try to use the delete Api via Postman as the docs say using that id:

POST https://myservicename.search.windows.net/indexes/myindexname/docs/index?api-version=2020-06-30   
Content-Type: application/json   
api-key: [my admin key]  
{  
  "value": [  
    {  
      "@search.action": "delete",  
      "id": "aHR0cHM6Ly9kYXRhbWluaW5nc2EuYmxvYi5jb3JlLndpbmRvd3MubmV0L2RvY3VtZW50YWwvcGxhbl9wcmVtaXVtX3YxODZ2Mi5w****"
    }
  ]  
} 

I got a "404 not found":

{
    "error": {
        "code": "",
        "message": "No HTTP resource was found that matches the request URI 'https://myservicename.search.windows.net/indexes('myindexname')/docs?api-version=2020-06-30'."
    }
}

Also, tried using fileName like this:

POST https://myservicename.search.windows.net/indexes/myindexname/docs/index?api-version=2020-06-30   
Content-Type: application/json   
api-key: [my admin key]  
{  
  "value": [  
    {  
      "@search.action": "delete",  
      "fileName": "deleted_file.pdf"
    }
  ]  
} 

Got the same result, don´t know why it tooked index inside parenthesis thoe, url it's well as above...I already enabled soft delete policy on index as well, files gone from storage but stills there on index...any idea ?

Upvotes: 0

Views: 227

Answers (2)

jsanchezs
jsanchezs

Reputation: 2070

Actually found the solution, that id extracted from Azure cognitive service portal inside the index query menu works perfectly, needed an url modification too using Preview version. I posted it here in case it could be helpful for someone else:

POST https://myservicename.search.windows.net/indexes/myindexname/docs/index?api-version=2020-06-30-Preview   
Content-Type: application/json   
api-key: [my admin key]  
{  
  "value": [  
    {  
      "@search.action": "delete",  
      "id": "doc id extracted from index"
    }
  ]  
} 

Upvotes: 1

Gia Mondragon - MSFT
Gia Mondragon - MSFT

Reputation: 466

Make sure you do not have ADLS Gen2 enabled on your Azure Storage account. Also, if you have enabled Soft-delete policy after your blobs were soft-deleted, make sure you change the blobs LastModified timestamp, so the policy is able to apply the changes to the index (https://learn.microsoft.com/en-us/azure/search/search-howto-index-changed-deleted-blobs)

Upvotes: 1

Related Questions