get_mappings
Get field mappings for a given Elasticsearch index, revealing the schema and data types of its fields.
Instructions
Get field mappings for a specific Elasticsearch index
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| index | Yes | Name of the Elasticsearch index to get mappings for |
Implementation Reference
- src/tools/getMappings.ts:3-42 (handler)The main handler function 'getMappings' that calls Elasticsearch's indices.getMapping API and returns the index mapping as formatted text content. Includes error handling with a catch block.
export async function getMappings(esClient: Client, index: string) { try { const mappingResponse = await esClient.indices.getMapping({ index, }); return { content: [ { type: "text" as const, text: `Index mapping: ${index}`, }, { type: "text" as const, text: `Index ${index} mapping: ${JSON.stringify( mappingResponse[index]?.mappings || {}, null, 2 )}`, }, ], }; } catch (error) { console.error( `Failed to get mapping: ${ 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:59-65 (schema)Input schema for the 'get_mappings' tool using Zod: requires a single 'index' parameter (trimmed string, min length 1).
{ index: z .string() .trim() .min(1, "Index name is required") .describe("Name of the Elasticsearch index to get mappings for"), }, - src/server.ts:56-69 (registration)Tool registration via server.tool() with name 'get_mappings', description 'Get field mappings for a specific Elasticsearch index', Zod schema, and handler that calls getMappings(esClient, index).
server.tool( "get_mappings", "Get field mappings for a specific Elasticsearch index", { index: z .string() .trim() .min(1, "Index name is required") .describe("Name of the Elasticsearch index to get mappings for"), }, async ({ index }) => { return await getMappings(esClient, index); } ); - src/server.ts:15-27 (helper)Module re-export of getMappings from the tools module index.
export { listIndices, getMappings, search, getClusterHealth, createIndex, createMapping, bulk, reindex, createIndexTemplate, getIndexTemplate, deleteIndexTemplate };