<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title><![CDATA[Walter Rafelsberger - Elasticsearch Labs]]></title>
    <description><![CDATA[Articles and tutorials from the Search team at Elastic]]></description>
    <copyright><![CDATA[© 2026. Elasticsearch B.V. All Rights Reserved]]></copyright>
    <image>
      <title><![CDATA[Walter Rafelsberger - Elasticsearch Labs]]></title>
      <url>https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt1121c0bf0e8a6e65/6a88da6340a1841030ef456f/search-labs-thumbnail.png</url>
      <link>https://www.elastic.co/cn/search-labs/author/walter-rafelsberger</link>
    </image>
    <link>https://www.elastic.co/cn/search-labs/author/walter-rafelsberger</link>
    <atom:link href="https://www.elastic.co/cn/search-labs/rss/author/walter-rafelsberger.xml" rel="self" type="application/rss+xml"/>
    <language><![CDATA[cn]]></language>
    <lastBuildDate>Tue, 29 Sep 2026 09:10:37 GMT</lastBuildDate>
  <item>
    <title><![CDATA[适用 Elasticsearch 的 Gemini CLI 扩展及工具和技能]]></title>
    <description><![CDATA[Elastic 推出了适用于谷歌 Gemini CLI 的扩展，用于在开发人员和智能体工作流中搜索、检索和分析 Elasticsearch 数据。
]]></description>
    <content:encoded><![CDATA[<p>我们很高兴地宣布， Elastic 发布了适用于 Google 的 Gemini CLI 扩展，将 <a href="https://www.elastic.co/elasticsearch">Elasticsearch</a> 和 <a href="https://www.elastic.co/elasticsearch/agent-builder">Elastic Agent Builder</a> 的全部功能直接引入您的 AI 开发工作流。此扩展还提供几种最近开发的智能体技能，用于与 Elasticsearch 交互。</p><p>该扩展以开源项目的形式在<a href="https://github.com/elastic/gemini-cli-elasticsearch">此处</a>提供。</p><h2>Gemini CLI 是什么？如何安装？</h2><p><a href="https://geminicli.com/">Gemini CLI</a> 是一个开源的 AI 智能体，它可将 Google 的 Gemini 模型直接引入命令行。它允许开发人员从终端与 AI 进行交互，以执行诸如生成代码、编辑文件、运行 shell 命令和从网上检索信息等任务。</p><p>与典型的聊天界面不同，Gemini CLI 可与您的本地开发环境集成，这意味着它可以直接在终端内理解项目上下文、修改文件、运行构建或测试，以及自动化工作流。这对于想要在不离开命令行工作流的情况下进行 AI 辅助编码和自动化的开发人员、网站可靠性工程师 (SREs) 和工程师来说非常有用。</p><p>Gemini CLI 可通过多个软件包管理器安装。最常用的方法是通过 npm 安装：</p>npm install -g @google/gemini-cli<p>如要了解其他安装选项，请参阅<a href="https://geminicli.com/docs/get-started/installation/">官方安装页面</a>。</p><p>安装完成后，运行以下命令启动 CLI：</p>gemini<p>您会看到一个屏幕，如图 1 所示：</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt4ff43abe550941b4/6a17072ba29299fc2ad00fa4/6dfcec4a77b3dc83bf0d974417bf2e211abb1f4f-876x468.png" alt="Gemini CLI 的屏幕截图。" /><h2>配置 Elasticsearch</h2><p>我们需要运行一个 Elasticsearch 实例。如要使用模型上下文协议 (MCP) 服务器，您还需要安装 Kibana 9.3+。如要使用下面描述的 Elasticsearch 查询语言 (ES|QL) 技能 (<code>esql</code>)，则不需要 Kibana。</p><p>您可以在 <a href="https://www.elastic.co/cloud">Elastic Cloud</a> 上激活免费试用版，或使用 <a href="https://github.com/elastic/start-local"><code>start-local</code></a> 脚本在本地安装：</p>curl -fsSL https://elastic.co/start-local | sh<p>这将在您的计算机上安装 Elasticsearch 和 Kibana，并生成一个用于配置 Gemini CLI 的 API 密钥。</p><p>API 密钥将显示为上一条命令的输出，并存储在 <strong>.env</strong> 文件中，该文件位于 <strong><code>elastic-start-local</code></strong> 文件夹。</p><p>如果您使用的是本地部署的 Elasticsearch（例如使用 <code>start-local</code>），并且您想将 Elastic Agent Builder 与 MCP 一起使用，那么您还需要连接一个大型语言模型 (LLM)。您可以阅读<a href="https://www.elastic.co/docs/explore-analyze/ai-features/llm-guides/llm-connectors">此文档页面</a>以了解不同的选项。</p><p>如果您使用的是 Elastic Cloud（或无服务器架构），那么您已经预先建立了 LLM 连接。</p><h2>安装 Elasticsearch 扩展</h2><p>您可以使用以下命令为 Gemini CLI 安装 Elasticsearch 扩展：</p>gemini extensions install https://github.com/elastic/gemini-cli-elasticsearch<p>您可以通过打开 Gemini 并执行以下命令来检查扩展程序是否已成功安装：</p>/extensions list<p>您应该看到 Elasticsearch 扩展可用。</p><p>如要使用 MCP 集成，您需要安装 Elasticsearch 9.3 或更高版本。您需要从 <a href="https://www.elastic.co/kibana">Kibana</a> 获取您的 MCP 服务器 URL：</p><ul><li><p>从智能体处获取 MCP 服务器 URL &gt; 查看所有工具 &gt; 管理 MCP &gt; 复制 MCP 服务器 URL。</p></li><li><p>URL 将如下所示：https://your-kibana-instance/api/agent_builder/mcp</p></li></ul><p>您需要 Elasticsearch 终端 URL。这通常显示在 Kibana Elasticsearch 页面的顶部。如果您使用 <code>start-local</code> 运行 Elasticsearch，那么您已经在 <code>start-local</code>.env 文件的<code>ES_LOCAL_URL</code> 密钥中拥有了终端。</p><p>您还需要一个 API 密钥。如果您使用 <code>start-local</code> 运行 Elasticsearch，那么您已经在 <code>start-local</code> .env 文件中拥有了 <code>ES_LOCAL_API_KEY</code>。否则，您可以使用 Kibana 界面创建 API 密钥，详见<a href="https://www.elastic.co/docs/deploy-manage/api-keys/elasticsearch-api-keys">此处</a>：</p><ul><li><p>在 Kibana 中：Stack Management &gt; Security &gt; API 密钥 &gt; 创建 API 密钥。</p></li><li><p>我们建议仅设置 API 密钥的读取权限，并启用 <code>feature_agentBuilder.read</code> 权限，详见<a href="https://www.elastic.co/docs/explore-analyze/ai-features/agent-builder/permissions#grant-access-with-roles">此处</a>。</p></li><li><p>复制已编码的 API 密钥值。</p></li></ul><p>在您的 shell 中设置所需的环境变量：</p>export ELASTIC_URL="your-elasticsearch-url"
export ELASTIC_MCP_URL="your-elasticsearch-mcp-url"
export ELASTIC_API_KEY="your-encoded-api-key"<h2>安装示例数据集</h2><p>您可以安装 Kibana 提供的<strong>电子商务订单</strong>数据集。它包含一个名为 <strong><code>kibana_sample_data_ecommerce</code></strong> 的单个索引，其中包含来自一家电子商务网站的 4675 个订单的信息。对于每笔订单，我们都有以下信息：</p><ul><li><p>客户信息（姓名、ID 号码、出生日期、电子邮件等）。</p></li><li><p>订单日期。</p></li><li><p>订单编号。</p></li><li><p>产品（包含价格、数量、ID、类别、折扣和其他详情的所有产品列表）</p></li><li><p>SKU。</p></li><li><p>总价（不含税，含税）。</p></li><li><p>总数量。</p></li><li><p>地理信息（城市、国家、洲、位置、地区）。</p></li></ul><p>如要安装示例数据，请在 Kibana 中打开<strong>集成</strong>页面（在顶部搜索栏中搜索“集成”），然后安装<strong>示例数据</strong>。更多详情请参阅<a href="https://www.elastic.co/docs/explore-analyze/#gs-get-data-into-kibana">此处</a>的文档。</p><p>本文旨在展示如何轻松配置 Gemini CLI 以连接到 Elasticsearch 并与 <strong><code>kibana_sample_data_ecommerce</code></strong> 索引交互。</p><h2>如何使用 Elasticsearch MCP（模型上下文协议）</h2><p>您可以在 Gemini 中使用以下命令检查连接：</p>/mcp list<p>您应该会看到 <strong><code>elastic-agent-builder</code></strong> 已启用，如图 2 所示：</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt52b85e7255360f3b/6a17072da929cf33d3ae08f5/1508423bc1d1bc3c04a1cb01e2d59495a3516ed1-1465x844.png" alt="`elastic-agent-builder` MCP 服务器及其工具列表。" /><p>Elasticsearch 提供了一组默认工具。请参阅<a href="https://www.elastic.co/docs/explore-analyze/ai-features/agent-builder/tools/builtin-tools-reference">此处</a>的描述。</p><p>使用这些工具，您可以与 Elasticsearch 进行交互，提出类似以下的问题：</p><ul><li><p><code>Give me the list of all the indexes available in Elasticsearch.</code></p></li><li><p><code>How many customers are based in the USA in the kibana_sample_data_ecommerce index of Elasticsearch?</code></p></li></ul><p>根据问题的不同，Gemini 会使用一个或多个可用工具来尝试回答问题。</p><h2>/elastic 命令</h2><p>在 Gemini CLI 的 Elasticsearch 扩展中，我们还添加了<strong><code>/elastic</code></strong> 命令。</p><p>如果执行 <strong><code>/help</code></strong> 命令，您将看到所有可用的 <code>/elastic</code> 选项（图 3）：</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt741c7451ecab10d2/6a17072ea6c2b9ccd6e79643/5b2a0727ce7a04354878dd048253d3f4d062324b-1983x230.png" alt="可用的 `/elastic` 命令。" /><p>这些命令在您想直接执行 <code>elastic-agent-builder</code> MCP 服务器的特定工具时会很有用。例如，使用以下命令可以获取 <code>kibana_sample_data_ecommerce</code> 的映射：</p>/elastic:get-mapping kibana_sample_data_ecommerce<p>这些命令本质上是执行特定工具的快捷方式，而不是依赖 Gemini 模型来确定应该调用哪个工具。</p><h2>如何使用 Elasticsearch 的技能？</h2><p>该扩展还附带了 ES|QL 的<a href="https://github.com/elastic/gemini-cli-elasticsearch/tree/main/skills/esql">代理技能，ES|QL</a> 是 Elasticsearch 中提供的 <a href="https://www.elastic.co/docs/explore-analyze/discover/try-esql">Elasticsearch 查询语言</a>。<a href="https://agentskills.io/home">Agent Skills</a> 是一种开放格式，为 AI 编码智能体（如 Gemini CLI）提供特定任务的自定义指令。它们使用一种称为<em>渐进式披露</em>的概念，即在系统初始提示中只添加对技能的简要说明。当您要求智能体执行任务时，比如查询 Elasticsearch，它会将请求与相关技能匹配，并动态加载详细说明。这是一种高效管理词元预算的方法，同时为 AI 提供所需的准确上下文。</p><p><strong><code>esql</code></strong><strong>技能</strong>旨在让 Gemini CLI 直接针对集群编写和执行 ES|QL 查询。ES|QL 是一种功能强大的管道化查询语言，能非常直观地进行数据探索、日志分析和聚合。启用该技能后，您无需查找 ES|QL 语法；只需用自然语言向 Gemini CLI 提出有关数据的问题，智能体会处理剩下的问题。</p><p>执行操作是通过在终端中运行简单的 <a href="https://curl.se/">curl</a> 命令来完成的。之所以能做到这一点，是因为 Elasticsearch 提供了一套丰富的 REST API，可轻松用于将系统集成到任何架构中。</p><p><strong> esql </strong><strong> 技能的功能：</strong></p><ul><li><p><strong>发现索引和模式：</strong>智能体可以使用该技能的内置工具列出可用索引并获取字段映射。例如，在为电子商务数据集编写查询之前，智能体可以在 <strong><code>kibana_sample_data_ecommerce</code></strong> 上运行模式检查，以了解可用的字段，如 <strong><code>taxful_total_price</code></strong> 或 <strong><code>category</code></strong>。</p></li><li><p><strong>无缝自然语言翻译：</strong>该技能不仅仅为智能体提供了一个简单的参考手册；它还提供了一个专门的指南，用于解读用户意图。当您用自然语言输入请求（如“按服务分组显示平均响应时间”）时，智能体会使用技能捆绑的模式匹配功能，将您的文字立即转换为正确的 ES|QL 聚合、筛选条件和命令。</p></li><li><p><strong>自我纠正：</strong>如果查询失败（例如由于类型不匹配或语法错误），该技能会返回生成的查询以及确切的 Elasticsearch 错误信息，使智能体能够立即修复查询并再次尝试，而无需您进行干预。</p></li></ul><p>由于 <code>esql</code> 技能也作为工具在 <code>elastic-agent-builder</code> MCP 服务器中可用，我们需要暂时禁用该服务器。您可以使用以下命令禁用它：</p>/mcp disable elastic-agent-builder<p>然后，您只需在 Gemini CLI 中输入类似这样的提示：</p>Find the top 5 product categories by total sales revenue in the kibana_sample_data_ecommerce index<p>代理将：</p><ul><li><p>认识到 <code>esql</code> 技能的必要性。</p></li><li><p>检查 <strong><code>kibana_sample_data_ecommerce</code></strong> 的模式。</p></li><li><p>构建一个 ES|QL 查询，比如：<code>FROM kibana_sample_data_ecommerce | STATS total_revenue = SUM(taxful_total_price) BY category.keyword | SORT total_revenue DESC | LIMIT 5</code>。</p></li><li><p>针对 Elasticsearch API 执行查询。</p></li><li><p>直接在终端中向您展示最终答案。</p></li></ul><p>在这里，我们分享了一个 Gemini 对先前提示的响应示例：</p>───────────────────────────────────────────────────────────
&gt; Find the top 5 product categories by total sales revenue in the kibana_sample_data_ecommerce index   ───────────────────────────────────────────────────────────
✓  Activate Skill "esql": Interact with Elasticsearch using ES|QL and curl. Use when querying, managing indices,  …
Skill esql activated. Resources loaded from /home/user/.gemini/extensions/elasticsearch/skills/esql: 
Showing up to 200 items (files + folders).                                                                     /home/user/.gemini/extensions/elasticsearch/skills/esql/                                                            ├───SKILL.md 
└───references/
├───esql-reference.md 
├───generation-tips.md 
└───query-patterns.md

✦ I will start by exploring the mapping of the kibana_sample_data_ecommerce index to identify the fields for product category and sales revenue. Then, I will construct and execute an ES|QL query to determine the top 5 product categories by total sales revenue.

✓  Shell curl -s "${ELASTIC_URL%/}/kibana_sample_data_ecommerce/_mapping" -H "Authorization: ApiKey $(printenv ELAS…                                                                                                                       {  
   "kibana_sample_data_ecommerce": { 
     "mappings": { 
       "properties": {
         "category": { 
           "type": "text", 
           "fields": {
             "keyword": {
               "type": "keyword"
             }
           }
         }, 
         "currency": {
           "type": "keyword"
         }, 

✦ Okay, I have the mapping. The category is products.category.keyword and sales revenue is taxful_total_price. I'll now execute the ES|QL query to get the top 5 categories by revenue.

✓  Shell curl -s -X POST "${ELASTIC_URL%/}/_query" \  -H "Authorization: ApiKey $(printenv ELASTIC_API_KEY)" \  -H …
{ 
   "took": 62,
   "is_partial": false, 
   "completion_time_in_millis": 1772805644164,
   "documents_found": 4675,
   "values_loaded": 12084, 
   "start_time_in_millis": 1772805644102, 
   "expiration_time_in_millis": 1773237644087,  
   "columns": [ 
     { 
       "name": "total_revenue",    
       "type": "double"  
     }, 
     {   
       "name": "products.category.keyword",

✦ The query for top 5 product categories by revenue was successful. I'll format the returned JSON values into a   user-friendly list.

 ✓  Shell 
                             
 Top 5 product categories by total sales revenue: 
 1. Men's Clothing: 149393.91
 2. Women's Clothing: 135099.91
 3. Women's Shoes: 105479.17
 4. Men's Shoes: 91797.92
 5. Women's Accessories: 60830.31 

✦ I've found the answer; now I'll format it for clarity.

 ✓  Shell 

 Here are the top 5 product categories by total sales revenue:                                                        
                                                                      
 | Rank | Category              | Total Revenue | 
 |------|-----------------------|---------------| 
 | 1    | Men's Clothing        | 149,393.91    |
 | 2    | Women's Clothing      | 135,099.91    |
 | 3    | Women's Shoes         | 105,479.17    |
 | 4    | Men's Shoes           | 91,797.92     | 
 | 5    | Women's Accessories   | 60,830.31     | 

✦ I've formatted and presented the answer. I'm finished.
 ───────────────────────────────────────────────────────────<p>值得注意的是，Gemini 模型如何通过显示其遵循的所有步骤来生成最终响应。在这里，您可以清楚地看到技能对模型推理过程的影响。当模型第一次意识到需要使用某项技能或执行 shell 命令时，它会采用人机协同的方式请求权限。</p><p>通过处理模式发现、查询生成和执行的繁重工作，<code>esql</code> 技能可以让您完全专注于答案，而不是获得答案的机制。您将获得所需的数据，格式正确且直接存储在终端中，无需写一行语法或切换到其他应用。</p><h2>结论</h2><p>在本文中，我们介绍了我们最近发布的适用于 Gemini CLI 的 Elasticsearch 扩展。此扩展让您可以使用 Gemini 和 Elastic Agent Builder 提供的 Elasticsearch MCP 服务器（从 9.3.0 版本开始提供）以及 <code>/elastic</code> 命令与您的 Elasticsearch 实例进行交互。</p><p>此外，该扩展还包含一项 <code>esql</code> 技能，可以将用户的自然语言请求转换为 ES|QL 查询。这种技能在无法使用 MCP 服务器时特别有用，因为底层通信是由在终端中执行的简单 curl 命令驱动的。Elasticsearch 提供了一套丰富的 REST API，可以轻松集成到任何项目中。这在开发智能体 AI 应用时尤为有用。</p><p>有关 Gemini CLI 扩展的更多信息，请访问<a href="https://github.com/elastic/gemini-cli-elasticsearch">此处</a>的项目库。</p>]]></content:encoded>
    <link>https://www.elastic.co/search-labs/blog/gemini-cli-extension-elasticsearch</link>
    <guid isPermaLink="true">https://www.elastic.co/search-labs/blog/gemini-cli-extension-elasticsearch</guid>
    <category><![CDATA[集成]]></category>
    <category><![CDATA[智能体 AI]]></category>
    <dc:creator><![CDATA[Walter Rafelsberger,Enrico Zimuel]]></dc:creator>
    <enclosure url="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt4ff43abe550941b4/6a17072ba29299fc2ad00fa4/6dfcec4a77b3dc83bf0d974417bf2e211abb1f4f-876x468.png" length="0" type="image/png"/>
    <pubDate>Tue, 17 Mar 2026 00:00:00 GMT</pubDate>
  </item>
  </channel>
</rss>