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")
    },
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action 'reindex' but doesn't describe what this entails operationally—whether it's a copy, move, or transformation process, potential performance impacts, error handling, or if it requires specific permissions. This is a significant gap for a tool that likely involves data manipulation.

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?

The description is a single, efficient sentence that front-loads the core action ('reindex data') and specifies the resources involved. There is no wasted verbiage, making it easy for an agent to parse quickly.

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

Completeness2/5

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

Given the complexity of a reindexing operation with 4 parameters (including nested objects), no annotations, and no output schema, the description is incomplete. It lacks details on behavior, error cases, performance implications, or what the tool returns, leaving the agent with insufficient context for safe and effective use.

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 description coverage is 100%, so the schema fully documents parameters like 'sourceIndex', 'destIndex', 'query', and 'script'. The description adds no additional meaning beyond the schema, such as explaining how 'query' filters data or how 'script' transforms documents. Baseline 3 is appropriate as the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the verb 'reindex' and the resource 'data from a source index to a target index', making the purpose immediately understandable. It distinguishes from siblings like 'bulk' or 'search' by focusing on index-to-index data transfer. However, it doesn't explicitly differentiate from potential overlap with 'create_index' or 'list_indices' in terms of when reindexing is specifically needed versus those operations.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., indices must exist), when reindexing is appropriate (e.g., for schema changes, data migration), or what alternatives might be (e.g., using 'bulk' for manual data transfer). This leaves the agent to infer usage from context alone.

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