delete_document
Remove a specific document from an Elasticsearch index by providing the index name and document ID for precise data management.
Instructions
Delete a document from a specific Elasticsearch index
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Document ID to delete | |
| index | Yes | Name of the Elasticsearch index |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"id": {
"description": "Document ID to delete",
"minLength": 1,
"type": "string"
},
"index": {
"description": "Name of the Elasticsearch index",
"minLength": 1,
"type": "string"
}
},
"required": [
"index",
"id"
],
"type": "object"
}
Implementation Reference
- src/index.ts:518-541 (handler)The main handler function for the "delete_document" MCP tool. It receives index and id parameters, calls the esService.deleteDocument helper, and returns a structured response with success or error message in MCP format.async ({ index, id }) => { try { await esService.deleteDocument(index, id); return { content: [ { type: "text", text: `Document with ID '${id}' deleted from index '${index}'.`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error deleting document: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }
- src/index.ts:507-517 (schema)Zod-based input schema defining the required 'index' and 'id' string parameters with validation and descriptions for the delete_document tool.{ index: z .string() .trim() .min(1, "Index name is required") .describe("Name of the Elasticsearch index"), id: z .string() .min(1, "Document ID is required") .describe("Document ID to delete"), },
- src/index.ts:504-542 (registration)The server.tool registration call for the "delete_document" tool, specifying name, description, input schema, and handler function.server.tool( "delete_document", "Delete a document from a specific Elasticsearch index", { index: z .string() .trim() .min(1, "Index name is required") .describe("Name of the Elasticsearch index"), id: z .string() .min(1, "Document ID is required") .describe("Document ID to delete"), }, async ({ index, id }) => { try { await esService.deleteDocument(index, id); return { content: [ { type: "text", text: `Document with ID '${id}' deleted from index '${index}'.`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error deleting document: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } );
- Supporting helper method in ElasticsearchService class that performs the actual document deletion using the Elasticsearch client.async deleteDocument(index: string, id: string): Promise<any> { return await this.client.delete({ index, id }); }