Skip to main content
Glama
awesimon

Elasticsearch MCP Server

create_index

Create an Elasticsearch index with configurable settings and mappings to organize and structure searchable data.

Instructions

Create an Elasticsearch index, optionally configure settings and mappings

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indexYesName of the Elasticsearch index to create
settingsNoIndex settings, such as number of shards and replicas
mappingsNoIndex mappings, defining field types, etc.

Implementation Reference

  • Handler function that executes the logic to create an Elasticsearch index with optional settings and mappings. Returns success or error content.
    export async function createIndex( esClient: Client, index: string, settings?: Record<string, any>, mappings?: Record<string, any> ) { try { const body: Record<string, any> = {}; if (settings) { body.settings = settings; } if (mappings) { body.mappings = mappings; } const response = await esClient.indices.create({ index, ...body }); const content: { type: "text"; text: string }[] = []; if (response.acknowledged) { content.push({ type: "text" as const, text: `索引 "${index}" 创建成功!\n分片数: ${response.shards_acknowledged ? '已确认' : '等待确认'}` }); } else { content.push({ type: "text" as const, text: `索引 "${index}" 创建请求已发送,但未得到确认。请检查集群状态。` }); } return { content }; } catch (error) { console.error(`创建索引失败: ${error instanceof Error ? error.message : String(error)}`); return { content: [ { type: "text" as const, text: `错误: ${error instanceof Error ? error.message : String(error)}` } ] }; } }
  • Zod schema defining the input parameters for the create_index tool: index (required string), settings (optional record), mappings (optional record).
    index: z .string() .trim() .min(1, "Index name is required") .describe("Name of the Elasticsearch index to create"), settings: z .record(z.any()) .optional() .describe("Index settings, such as number of shards and replicas"), mappings: z .record(z.any()) .optional() .describe("Index mappings, defining field types, etc.") },
  • src/server.ts:123-146 (registration)
    MCP server.tool registration for 'create_index', providing description, input schema, and handler function.
    server.tool( "create_index", "Create an Elasticsearch index, optionally configure settings and mappings", { index: z .string() .trim() .min(1, "Index name is required") .describe("Name of the Elasticsearch index to create"), settings: z .record(z.any()) .optional() .describe("Index settings, such as number of shards and replicas"), mappings: z .record(z.any()) .optional() .describe("Index mappings, defining field types, etc.") }, async ({ index, settings, mappings }) => { return await createIndex(esClient, index, settings, mappings); } );

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/awesimon/elasticsearch-mcp'

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