Elasticsearch Semantic Search MCP Server

by jedrazb
Verified

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Integrations

  • The MCP server provides semantic search functionality through Elasticsearch, enabling users to search through Search Labs blog posts that have been indexed using Elastic Open Crawler.

MCP 服务器:Elasticsearch 语义搜索工具

演示 repo: https://j.blaszyk.me/tech-blog/mcp-server-elasticsearch-semantic-search/

目录


概述

该存储库提供了一个 MCP 服务器的 Python 实现,用于通过Elasticsearch中索引的Search Labs 博客文章进行语义搜索

它假设您已经使用Elastic Open Crawler抓取了博客文章并将其存储在search-labs-posts索引中。


运行 MCP 服务器

ES_URLES_AP_KEY添加到.env文件中,(查看此处了解如何生成具有最低权限的 api 密钥)

MCP Inspector中启动服务器:

make dev

运行后,访问 MCP Inspector: http://localhost:5173


与 Claude Desktop 集成

要将 MCP 服务器添加到Claude Desktop

make install-claude-config

这会更新你主目录中的claude_desktop_config.json 。下次重启后,Claude 应用将检测服务器并加载声明的工具。


抓取搜索实验室博客文章

1. 验证爬虫设置

要检查Elastic Open Crawler是否工作,请运行:

docker run --rm \ --entrypoint /bin/bash \ -v "$(pwd)/crawler-config:/app/config" \ --network host \ docker.elastic.co/integrations/crawler:latest \ -c "bin/crawler crawl config/test-crawler.yml"

这应该从单个页面打印抓取的内容。


2.配置Elasticsearch

设置Elasticsearch URL 和 API Key

生成具有最低爬虫权限的 API 密钥:

POST /_security/api_key { "name": "crawler-search-labs", "role_descriptors": { "crawler-search-labs-role": { "cluster": ["monitor"], "indices": [ { "names": ["search-labs-posts"], "privileges": ["all"] } ] } }, "metadata": { "application": "crawler" } }

从响应中复制encoded值并将其设置为API_KEY


3. 更新语义搜索的索引映射

确保search-labs-posts索引存在。如果不存在,请创建它:

PUT search-labs-posts

更新映射以启用语义搜索

PUT search-labs-posts/_mappings { "properties": { "body": { "type": "text", "copy_to": "semantic_body" }, "semantic_body": { "type": "semantic_text", "inference_id": ".elser-2-elasticsearch" } } }

使用Elasticsearch 的 ELSER 模型body字段索引为语义文本


4.开始爬行

运行爬虫来填充索引:

docker run --rm \ --entrypoint /bin/bash \ -v "$(pwd)/crawler-config:/app/config" \ --network host \ docker.elastic.co/integrations/crawler:latest \ -c "bin/crawler crawl config/elastic-search-labs-crawler.yml"

[!TIP]如果使用新的 Elasticsearch 集群,请等待ELSER 模型启动后再进行索引。


5.验证索引文档

检查文档是否已被索引:

GET search-labs-posts/_count

这将返回索引中的文档总数。您也可以在Kibana中验证。


完成!您现在可以对Search Labs 博客文章进行语义搜索了

-
security - not tested
F
license - not found
-
quality - not tested

一个 Python MCP 服务器,可以通过 Elasticsearch 中索引的 Search Labs 博客文章进行语义搜索,从而允许 Claude 从博客内容中智能地检索相关信息。

  1. Table of Contents
    1. Overview
      1. Running the MCP Server
        1. Integrating with Claude Desktop
          1. Crawling Search Labs Blog Posts
            1. 1. Verify Crawler Setup
            2. 2. Configure Elasticsearch
            3. 3. Update Index Mapping for Semantic Search
            4. 4. Start Crawling
            5. 5. Verify Indexed Documents
          ID: ovfbwy77z2