get_mappings
Retrieve field mappings for a specified Elasticsearch index to understand its data structure and schema. Input the index name to access detailed mappings.
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/index.ts:154-187 (handler)Handler function that executes the get_mappings tool: calls esService.getMappings(index), formats success/error response with JSON mappings.async ({ index }) => { try { const mappings = await esService.getMappings(index); return { content: [ { type: "text", text: `Mappings for index: ${index}`, }, { type: "text", text: JSON.stringify(mappings, null, 2), }, ], }; } catch (error) { console.error( `Failed to get mappings: ${ error instanceof Error ? error.message : String(error) }` ); return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }
- src/index.ts:147-153 (schema)Input schema for get_mappings tool: requires 'index' string parameter.{ index: z .string() .trim() .min(1, "Index name is required") .describe("Name of the Elasticsearch index to get mappings for"), },
- src/index.ts:144-188 (registration)Registration of the get_mappings tool using server.tool(name, description, schema, handler).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 }) => { try { const mappings = await esService.getMappings(index); return { content: [ { type: "text", text: `Mappings for index: ${index}`, }, { type: "text", text: JSON.stringify(mappings, null, 2), }, ], }; } catch (error) { console.error( `Failed to get mappings: ${ error instanceof Error ? error.message : String(error) }` ); return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } );
- Helper method in ElasticsearchService that calls the Elasticsearch indices.getMapping API and extracts mappings for the given index.async getMappings(index: string): Promise<any> { const response = await this.client.indices.getMapping({ index, }); return response[index]?.mappings || {}; }