Skip to main content
Glama
awesimon

Elasticsearch MCP Server

reindex

Copies documents from a source Elasticsearch index to a target index, with optional query filtering and script-based transformation.

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

  • The main handler function for the reindex tool. It takes an Elasticsearch client, source index, destination index, optional script, and optional query. It creates a ReindexRequest (with wait_for_completion: false for async operation), optionally adds query/script filters, calls the esClient.reindex() API, and returns a response with the task ID and 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)}`
            }
          ]
        };
      }
    } 
  • Input schema definition for the reindex tool, defined via Zod. Requires sourceIndex and destIndex (both trimmed non-empty strings), and optionally accepts query and script (both Record<string, any>).
    {
      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")
    },
  • src/server.ts:194-224 (registration)
    Registration of the 'reindex' tool on the MCP server using server.tool(), binding the schema to the async handler that calls reindex().
    // Reindex from source to target index with optional query and script
    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);
      }
    );
  • src/server.ts:12-12 (registration)
    Import statement for the reindex function from ./tools/reindex.js
    import { reindex } from "./tools/reindex.js";
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided; description does not disclose behavioral traits such as whether the operation is synchronous, whether it overwrites or appends to the target index, or potential side effects like cluster load.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence with no extraneous information; concise and front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the straightforward nature of reindexing and that all parameters have good schema descriptions, the description is adequate but lacks details on return values (no output schema) and behavioral context (e.g., would benefit from mention of async or copying behavior).

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema descriptions are clear for all four parameters (100% coverage), so baseline is 3. The description adds minimal value beyond the schema, only restating the overall operation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses the verb 'Reindex' and specifies the resource as 'data from a source index to a target index', clearly distinguishing this tool from siblings like 'bulk' (bulk indexing) and 'create_index' (creating an index).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives (e.g., using search and bulk operations), no prerequisites mentioned (e.g., indices must exist), and no context on performance implications or long-running nature.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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