get_index_template
Retrieve details about Elasticsearch index templates, with an optional filter by template name to narrow results.
Instructions
Get information about Elasticsearch index templates
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No | Optional template name filter - if omitted, all templates are returned |
Implementation Reference
- src/tools/createIndexTemplate.ts:66-120 (handler)The main handler function 'getIndexTemplate' that executes the tool logic. It accepts an optional 'name' parameter, calls esClient.indices.getIndexTemplate(), formats the response with template name, index patterns, version, and priority, and returns content. Includes error handling.
export async function getIndexTemplate( esClient: Client, name?: string ) { try { const params: Record<string, any> = {}; if (name) { params.name = name; } const response = await esClient.indices.getIndexTemplate(params); const templates = response.index_templates || []; const content = templates.map(template => { const patterns = template.index_template.index_patterns || []; const version = template.index_template.version || "Not specified"; const priority = template.index_template.priority || "Not specified"; let patternsText = ""; if (Array.isArray(patterns)) { patternsText = patterns.join(", "); } else if (typeof patterns === "string") { patternsText = patterns; } return { type: "text" as const, text: `Template: ${template.name}\nIndex patterns: ${patternsText}\nVersion: ${version}\nPriority: ${priority}\n` }; }); if (content.length === 0) { content.push({ type: "text" as const, text: name ? `No template found with name "${name}"` : "No index templates found" }); } return { content }; } catch (error) { console.error(`Get 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:261-274 (registration)Registration of the 'get_index_template' tool via server.tool(). Defines the schema (optional 'name' string) and calls the getIndexTemplate handler function.
// Get index templates server.tool( "get_index_template", "Get information about Elasticsearch index templates", { name: z .string() .optional() .describe("Optional template name filter - if omitted, all templates are returned") }, async ({ name }) => { return await getIndexTemplate(esClient, name); } ); - src/server.ts:265-270 (schema)Input schema for the 'get_index_template' tool: an optional 'name' string parameter to filter by template name.
{ name: z .string() .optional() .describe("Optional template name filter - if omitted, all templates are returned") }, - src/server.ts:13-13 (helper)Import of getIndexTemplate from the tools file into server.ts.
import { createIndexTemplate, getIndexTemplate, deleteIndexTemplate } from "./tools/createIndexTemplate.js";