Skip to main content
Glama
Octodet

octodet-elasticsearch-mcp

update_document

Modify specific fields in an existing document within an Elasticsearch index by providing the index name, document ID, and updated content.

Instructions

Update an existing document in a specific Elasticsearch index

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
documentYesPartial document body to update (fields to change)
idYesDocument ID to update
indexYesName of the Elasticsearch index

Implementation Reference

  • MCP tool handler for 'update_document' that validates input, calls the Elasticsearch service, and formats success/error responses.
    async ({ index, id, document }) => {
      try {
        await esService.updateDocument(index, id, document);
        return {
          content: [
            {
              type: "text",
              text: `Document with ID '${id}' updated in index '${index}'.`,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error updating document: ${
                error instanceof Error ? error.message : String(error)
              }`,
            },
          ],
        };
      }
    }
  • Zod schema defining input parameters for the update_document tool: index (string), id (string), document (record).
    {
      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 update"),
      document: z
        .record(z.any())
        .describe("Partial document body to update (fields to change)"),
    },
  • src/index.ts:460-501 (registration)
    Registration of the 'update_document' tool on the MCP server using server.tool(), including name, description, schema, and handler.
    server.tool(
      "update_document",
      "Update an existing document in 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 update"),
        document: z
          .record(z.any())
          .describe("Partial document body to update (fields to change)"),
      },
      async ({ index, id, document }) => {
        try {
          await esService.updateDocument(index, id, document);
          return {
            content: [
              {
                type: "text",
                text: `Document with ID '${id}' updated in index '${index}'.`,
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error updating document: ${
                  error instanceof Error ? error.message : String(error)
                }`,
              },
            ],
          };
        }
      }
    );
  • Helper function in ElasticsearchService that executes the actual Elasticsearch client update operation.
    async updateDocument(index: string, id: string, document: any): Promise<any> {
      return await this.client.update({
        index,
        id,
        doc: document,
      });
    }
Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Octodet/elasticsearch-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server