index_document
Add or update documents in an Elasticsearch index. Specify the index name, document data, and optional ID to manage data efficiently with the MCP Server.
Instructions
Creates or updates a document in the index.
Args:
index: Name of the index
document: Document data
id: Optional document ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| document | Yes | ||
| id | No | ||
| index | Yes |
Implementation Reference
- src/tools/document.py:22-31 (handler)MCP tool handler for 'index_document'. Delegates to the search client's index_document method to create or update a document.def index_document(index: str, document: Dict, id: Optional[str] = None) -> Dict: """ Creates or updates a document in the index. Args: index: Name of the index document: Document data id: Optional document ID """ return self.search_client.index_document(index=index, id=id, document=document)
- src/clients/common/document.py:10-24 (helper)Core helper implementation of index_document in DocumentClient class, handling engine-specific parameter mapping for Elasticsearch and OpenSearch.def index_document(self, index: str, document: Dict, id: Optional[str] = None) -> Dict: """Creates a new document in the index.""" # Handle parameter name differences between Elasticsearch and OpenSearch if self.engine_type == "elasticsearch": # For Elasticsearch: index(index, document, id=None, ...) if id is not None: return self.client.index(index=index, document=document, id=id) else: return self.client.index(index=index, document=document) else: # For OpenSearch: index(index, body, id=None, ...) if id is not None: return self.client.index(index=index, body=document, id=id) else: return self.client.index(index=index, body=document)
- src/server.py:44-54 (registration)DocumentTools (containing the index_document handler) is registered by including it in the tool_classes list passed to ToolsRegister.register_all_tools.tool_classes = [ IndexTools, DocumentTools, ClusterTools, AliasTools, DataStreamTools, GeneralTools, ] # Register all tools register.register_all_tools(tool_classes)
- src/risk_config.py:15-19 (helper)'index_document' is listed as a high-risk operation for DocumentTools in the risk configuration."DocumentTools": { "index_document", "delete_document", "delete_by_query", },