Overview
PurposeFinds all Azure AI Search index chunks belonging to a given
document_id and deletes them in a single batch operation.MethodPOST
AuthHeader —
api-key: ankitg.inContent-TypeNo body required (all params are headers)
Endpoint
Request Headers
| Header | Required | Type | Description |
|---|---|---|---|
api-key |
Required | String | Lab API key. Hardcoded value: ankitg.in |
azureAISearchEndpoint |
Required | String (URL) | Base URL of your Azure AI Search service, e.g. https://my-search.search.windows.net |
azureAISearchKey |
Required | String | Admin or query key for your Azure AI Search service |
indexName |
Required | String | Name of the Azure AI Search index to target |
document_id |
Required | Integer | Numeric ID of the document whose chunks should be deleted |
How It Works
| Step | Action |
|---|---|
| 1 | Validates all required headers. Returns 400 if any are missing or document_id is non-numeric. |
| 2 | Calls Azure AI Search Search API with filter document_id eq {value} to retrieve up to 1,000 matching chunk IDs. |
| 3 | If no chunks are found, returns success with deleted_chunks: 0. |
| 4 | Calls Azure AI Search Index API with @search.action: "delete" for each chunk ID in a single batch request. |
| 5 | Returns a JSON response with success, message, and deleted_chunks count. |
Sample Requests
cURL
# Delete all indexed chunks for document_id 42 curl -X POST https://labs.lowcademy.com/apis/delete-indexed-document.php \ -H "api-key: ankitg.in" \ -H "azureAISearchEndpoint: https://my-search.search.windows.net" \ -H "azureAISearchKey: YOUR_SEARCH_ADMIN_KEY" \ -H "indexName: my-documents-index" \ -H "document_id: 42"
JavaScript (fetch)
const response = await fetch('https://labs.lowcademy.com/apis/delete-indexed-document.php', { method: 'POST', headers: { 'api-key': 'ankitg.in', 'azureAISearchEndpoint': 'https://my-search.search.windows.net', 'azureAISearchKey': 'YOUR_SEARCH_ADMIN_KEY', 'indexName': 'my-documents-index', 'document_id': '42', } }); const result = await response.json(); console.log(result);
OutSystems (REST API call)
// Method: POST // URL: https://labs.lowcademy.com/apis/delete-indexed-document.php // Headers (map from OutSystems input parameters): api-key → "ankitg.in" // hardcoded azureAISearchEndpoint → AzureAISearchEndpoint // Text input azureAISearchKey → AzureAISearchKey // Text input indexName → IndexName // Text input document_id → DocumentId // Integer input → ToString
Response Schema
Success — chunks deleted (HTTP 200)
{
"success": true,
"message": "Successfully deleted 7 chunk(s) for document_id 42 from index 'my-documents-index'.",
"deleted_chunks": 7
}
Success — nothing to delete (HTTP 200)
{
"success": true,
"message": "No indexed chunks found for document_id 42. Nothing was deleted.",
"deleted_chunks": 0
}
Error (HTTP 4xx / 5xx)
{
"success": false,
"message": "Missing required header: indexName."
}
Response Codes
| Code | Meaning |
|---|---|
200 | Success — chunks deleted, or no chunks found (both are non-error states) |
400 | Missing or invalid header parameter |
401 | Invalid or missing api-key |
405 | Wrong HTTP method (use POST) |
502 | Azure AI Search returned an error (search or delete call failed) |
Notes
Batch limit: Up to 1,000 chunks per document are deleted in a single Azure AI Search batch call. Documents with more than 1,000 chunks would require multiple calls (not expected in typical usage — a 1,200-char chunk of a 300-page PDF produces ~750 chunks at most).
document_id filter: Azure AI Search uses OData filter syntax for Int64 fields — the value must be unquoted:
document_id eq 42 (not document_id eq '42'). This API handles that automatically.
Idempotent: Calling this API twice for the same
document_id is safe. The second call returns deleted_chunks: 0 with success.