get_mappings
Retrieve field mappings for an Elasticsearch index to understand data structure and types.
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 fetches the mappings for the specified Elasticsearch index using esClient.indices.getMapping and returns a formatted text response with the mappings or an error message.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:180-186 (schema)Input schema for the get_mappings tool, which validates that the 'index' parameter is 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:178-228 (registration)Registration of the get_mappings tool using server.tool(), including name, description, input schema, and handler function."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) }`, }, ], }; } } );