Skip to main content
Glama
awesimon

Elasticsearch MCP Server

create_index_template

Define or modify Elasticsearch index templates to manage settings, mappings, and aliases for specific index patterns using the Elasticsearch MCP Server.

Instructions

Create or update an Elasticsearch index template

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indexPatternsYesArray of index patterns this template applies to
nameYesName of the index template
priorityNoOptional template priority - higher values have higher precedence
templateYesTemplate configuration including settings, mappings, and aliases
versionNoOptional template version number

Implementation Reference

  • The core handler function that implements the logic for creating an Elasticsearch index template using the Elasticsearch client.
    export async function createIndexTemplate( esClient: Client, name: string, indexPatterns: string[], template: Record<string, any>, priority?: number, version?: number ) { try { const body: Record<string, any> = { index_patterns: indexPatterns, template: { settings: template.settings || {}, mappings: template.mappings || {}, aliases: template.aliases || {} } }; // Add optional parameters if provided if (priority !== undefined) { body.priority = priority; } if (version !== undefined) { body.version = version; } const response = await esClient.indices.putIndexTemplate({ name, body }); return { content: [ { type: "text" as const, text: `Index template "${name}" created successfully.` }, { type: "text" as const, text: `Index patterns: ${indexPatterns.join(", ")}` }, { type: "text" as const, text: response.acknowledged ? "Template was acknowledged by the cluster." : "Template was not acknowledged. Check cluster status." } ] }; } catch (error) { console.error(`Create index template 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:226-259 (registration)
    Registers the 'create_index_template' tool with the MCP server, defining the input schema using Zod and wiring the handler function.
    // Create or update an index template server.tool( "create_index_template", "Create or update an Elasticsearch index template", { name: z .string() .trim() .min(1, "Template name is required") .describe("Name of the index template"), indexPatterns: z .array(z.string()) .min(1, "At least one index pattern is required") .describe("Array of index patterns this template applies to"), template: z .record(z.any()) .describe("Template configuration including settings, mappings, and aliases"), priority: z .number() .optional() .describe("Optional template priority - higher values have higher precedence"), version: z .number() .optional() .describe("Optional template version number") }, async ({ name, indexPatterns, template, priority, version }) => { return await createIndexTemplate(esClient, name, indexPatterns, template, priority, version); } );
  • Zod schema definitions for the input parameters of the create_index_template tool.
    name: z .string() .trim() .min(1, "Template name is required") .describe("Name of the index template"), indexPatterns: z .array(z.string()) .min(1, "At least one index pattern is required") .describe("Array of index patterns this template applies to"), template: z .record(z.any()) .describe("Template configuration including settings, mappings, and aliases"), priority: z .number() .optional() .describe("Optional template priority - higher values have higher precedence"), version: z .number() .optional() .describe("Optional template version number") }, async ({ name, indexPatterns, template, priority, version }) => { return await createIndexTemplate(esClient, name, indexPatterns, template, priority, version); } );

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

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