Skip to main content
Glama
awesimon

Elasticsearch MCP Server

reindex

Copies documents from one Elasticsearch index to another, with optional filtering and transformation during the process.

Instructions

Reindex data from a source index to a target index

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceIndexYesName of the source Elasticsearch index
destIndexYesName of the destination Elasticsearch index
queryNoOptional query to filter which documents to reindex
scriptNoOptional script to transform documents during reindex

Implementation Reference

  • Core handler function that performs the Elasticsearch reindex operation asynchronously, with optional query and script support, returning task ID and monitoring instructions.
    export async function reindex( esClient: Client, sourceIndex: string, destIndex: string, script?: Record<string, any>, query?: Record<string, any> ) { try { const reindexRequest: estypes.ReindexRequest = { source: { index: sourceIndex }, dest: { index: destIndex }, wait_for_completion: false // Async operation for large indices }; // Add query if provided if (query) { reindexRequest.source.query = query; } // Add script if provided if (script) { reindexRequest.script = script; } const response = await esClient.reindex(reindexRequest); const taskId = response.task; return { content: [ { type: "text" as const, text: `Reindex operation started. Task ID: ${taskId}` }, { type: "text" as const, text: `Source index: ${sourceIndex} -> Destination index: ${destIndex}` }, { type: "text" as const, text: `Use Task API to monitor progress: GET _tasks/${taskId}` } ] }; } catch (error) { console.error(`Reindex operation failed: ${error instanceof Error ? error.message : String(error)}`); return { content: [ { type: "text" as const, text: `Error: ${error instanceof Error ? error.message : String(error)}` } ] }; } }
  • src/server.ts:195-224 (registration)
    MCP server tool registration for 'reindex', including Zod input schema validation and binding to the reindex handler function.
    server.tool( "reindex", "Reindex data from a source index to a target index", { sourceIndex: z .string() .trim() .min(1, "Source index name is required") .describe("Name of the source Elasticsearch index"), destIndex: z .string() .trim() .min(1, "Destination index name is required") .describe("Name of the destination Elasticsearch index"), query: z .record(z.any()) .optional() .describe("Optional query to filter which documents to reindex"), script: z .record(z.any()) .optional() .describe("Optional script to transform documents during reindex") }, async ({ sourceIndex, destIndex, query, script }) => { return await reindex(esClient, sourceIndex, destIndex, script, query); } );
  • Zod schema for 'reindex' tool inputs: required sourceIndex and destIndex strings, optional query and script objects.
    { sourceIndex: z .string() .trim() .min(1, "Source index name is required") .describe("Name of the source Elasticsearch index"), destIndex: z .string() .trim() .min(1, "Destination index name is required") .describe("Name of the destination Elasticsearch index"), query: z .record(z.any()) .optional() .describe("Optional query to filter which documents to reindex"), script: z .record(z.any()) .optional() .describe("Optional script to transform documents during reindex") },

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/awesimon/elasticsearch-mcp'

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