Skip to main content
Glama
Octodet

octodet-elasticsearch-mcp

create_index

Define and configure Elasticsearch index with custom settings and field mappings for efficient data organization and retrieval.

Instructions

Create a new Elasticsearch index with optional settings and mappings

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indexYesName of the new Elasticsearch index to create
mappingsNoOptional index mappings defining field types and properties
settingsNoOptional index settings like number of shards, replicas, etc.

Implementation Reference

  • The handler function for the 'create_index' tool. It calls esService.createIndex with the provided index name, settings, and mappings, then returns a success message or error.
    async ({ index, settings, mappings }) => { try { const response = await esService.createIndex(index, settings, mappings); return { content: [ { type: "text", text: `Index '${index}' created successfully.`, }, ], }; } catch (error) { console.error( `Failed to create index: ${ error instanceof Error ? error.message : String(error) }` ); return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }
  • Input schema for the 'create_index' tool using Zod, defining parameters: index (required string), settings (optional record), mappings (optional record).
    { index: z .string() .trim() .min(1, "Index name is required") .describe("Name of the new Elasticsearch index to create"), settings: z .record(z.any()) .optional() .describe( "Optional index settings like number of shards, replicas, etc." ), mappings: z .record(z.any()) .optional() .describe( "Optional index mappings defining field types and properties" ), },
  • src/index.ts:938-988 (registration)
    Registration of the 'create_index' tool using server.tool(), including name, description, input schema, and handler function.
    "create_index", "Create a new Elasticsearch index with optional settings and mappings", { index: z .string() .trim() .min(1, "Index name is required") .describe("Name of the new Elasticsearch index to create"), settings: z .record(z.any()) .optional() .describe( "Optional index settings like number of shards, replicas, etc." ), mappings: z .record(z.any()) .optional() .describe( "Optional index mappings defining field types and properties" ), }, async ({ index, settings, mappings }) => { try { const response = await esService.createIndex(index, settings, mappings); return { content: [ { type: "text", text: `Index '${index}' created successfully.`, }, ], }; } catch (error) { console.error( `Failed to create index: ${ error instanceof Error ? error.message : String(error) }` ); return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } );
  • The ElasticsearchService.createIndex method, which performs the actual index creation using the Elasticsearch client, incorporating optional settings and mappings.
    async createIndex( index: string, settings?: any, mappings?: any ): Promise<any> { const body: any = {}; if (settings) { body.settings = settings; } if (mappings) { body.mappings = mappings; } return await this.client.indices.create({ index, ...(Object.keys(body).length > 0 ? { body } : {}), }); }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Octodet/elasticsearch-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server