delete_by_query
Delete Elasticsearch documents matching a specific query to remove targeted data from an index.
Instructions
Deletes documents matching the provided query.
Args:
index: Name of the index
body: Query to match documents for deletion
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| index | Yes | ||
| body | Yes |
Implementation Reference
- src/tools/document.py:55-64 (handler)The main MCP tool handler for delete_by_query. Decorated with @mcp.tool() for registration and execution. Delegates to the search_client's delete_by_query method.@mcp.tool() def delete_by_query(index: str, body: Dict) -> Dict: """ Deletes documents matching the provided query. Args: index: Name of the index body: Query to match documents for deletion """ return self.search_client.delete_by_query(index=index, body=body)
- src/clients/common/document.py:34-36 (helper)Supporting method in DocumentClient class that proxies the delete_by_query call to the underlying Elasticsearch/OpenSearch client.def delete_by_query(self, index: str, body: Dict) -> Dict: """Deletes documents matching the provided query.""" return self.client.delete_by_query(index=index, body=body)
- src/server.py:40-53 (registration)Central registration point where DocumentTools (containing delete_by_query) is included in the list of tool classes to register with the MCP server.# Create a tools register register = ToolsRegister(self.logger, self.search_client, self.mcp) # Define all tool classes to register tool_classes = [ IndexTools, DocumentTools, ClusterTools, AliasTools, DataStreamTools, GeneralTools, ] # Register all tools register.register_all_tools(tool_classes)