get_mappings
Retrieve field mappings for an Elasticsearch index to understand data structure and field types for querying and analysis.
Instructions
Get field mappings for a specific Elasticsearch index
Input Schema
TableJSON 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 handler function that fetches Elasticsearch index mappings using the Elasticsearch client and returns formatted text content with the mappings or error message.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:56-69 (registration)The registration of the 'get_mappings' tool on the MCP server, including description, input schema, and handler invocation.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:60-65 (schema)Zod schema for the input parameter 'index' of the 'get_mappings' tool.index: z .string() .trim() .min(1, "Index name is required") .describe("Name of the Elasticsearch index to get mappings for"), },