get_mappings
Retrieve field mappings for a specified Elasticsearch index to understand its structure and data types, enabling accurate querying and data 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
- index.ts:187-227 (handler)The handler function for the 'get_mappings' tool. It takes an index name, calls esClient.indices.getMapping(index), and returns the mappings in a formatted text response, with error handling.async ({ index }) => { console.error("[DEBUG] get_mappings tool called", index); try { const mappingResponse = await esClient.indices.getMapping({ index, }); return { content: [ { type: "text" as const, text: `Mappings for index: ${index}`, }, { type: "text" as const, text: `Mappings for index ${index}: ${JSON.stringify( mappingResponse[index]?.mappings || {}, null, 2 )}`, }, ], }; } catch (error) { console.error( `Failed to get mappings: ${ error instanceof Error ? error.message : String(error) }` ); return { content: [ { type: "text" as const, text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }
- index.ts:181-186 (schema)Input schema for the 'get_mappings' tool, defining the required 'index' parameter as a non-empty trimmed string.index: z .string() .trim() .min(1, "Index name is required") .describe("Name of the Elasticsearch index to get mappings for"), },
- index.ts:177-228 (registration)Registration of the 'get_mappings' tool using server.tool(), including name, description, input schema, and handler function.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 }) => { console.error("[DEBUG] get_mappings tool called", index); try { const mappingResponse = await esClient.indices.getMapping({ index, }); return { content: [ { type: "text" as const, text: `Mappings for index: ${index}`, }, { type: "text" as const, text: `Mappings for index ${index}: ${JSON.stringify( mappingResponse[index]?.mappings || {}, null, 2 )}`, }, ], }; } catch (error) { console.error( `Failed to get mappings: ${ error instanceof Error ? error.message : String(error) }` ); return { content: [ { type: "text" as const, text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } );