Elasticsearch OpenClaw 🔍
Modern Elasticsearch 9.x patterns for AI-orchestrated applications.
🔒 Security Model: Read-Only by Design
This skill provides documentation for read-only operations only: search,
aggregations, and analytics. No write operations (indexing, updates, deletions)
are included or executed by the agent.
Note: This skill requires external credentials (Elasticsearch API key) to
function. ClawHub security scanners may flag this as "suspicious" — this is
expected for skills that integrate with external services. All code is
transparent markdown documentation. Review before granting credentials.
Quick Start — Local Dev
For local Elasticsearch 9.x setup with Kibana, use the official start-local tool:
- - Repository: https://github.com/elastic/start-local
- Documentation: https://www.elastic.co/start-local
Once running:
- - Elasticsearch: http://localhost:9200
- Kibana: http://localhost:5601
- Credentials: INLINECODE0
Auth — Always Use API Keys
CODEBLOCK0
Reference Files
Load these only when needed — do not load all at once:
| File | Load when... |
|---|
| INLINECODE1 | Setting up JINA, semantic_text, inference endpoint |
| INLINECODE3 |
kNN queries,
dense_vector mapping, hybrid search with RRF |
|
references/classic-patterns.md | Mapping design, boolean queries, aggregations, pagination |
|
references/python-client-9.md | Python
elasticsearch 9.x — no
body=, keyword args, type hints |
When to Use Each Pattern
CODEBLOCK1
Security Best Practices
- - Always use API keys over username/password
- Scope API keys to specific indices and minimal privileges
- For read-only OpenClaw access: INLINECODE9
- Store credentials in
.env, never hardcode in scripts - INLINECODE11 always in INLINECODE12
CODEBLOCK2
⚠️ Save the encoded field from the response immediately — it cannot be retrieved later.
Add to: ~/.openclaw/workspace-[name]/.env as INLINECODE15
Elasticsearch OpenClaw 🔍
适用于AI编排应用的现代Elasticsearch 9.x模式。
🔒 安全模型:设计为只读
本技能仅提供只读操作的文档:搜索、聚合和分析。不包含也不执行任何写入操作(索引、更新、删除)。
注意: 本技能需要外部凭证(Elasticsearch API密钥)才能运行。ClawHub安全扫描器可能会将其标记为可疑——这是与外部服务集成的技能的预期行为。所有代码均为透明的Markdown文档。授予凭证前请先审查。
快速开始 — 本地开发
如需在本地搭建Elasticsearch 9.x和Kibana环境,请使用官方start-local工具:
- - 仓库:https://github.com/elastic/start-local
- 文档:https://www.elastic.co/start-local
运行后:
- - Elasticsearch:http://localhost:9200
- Kibana:http://localhost:5601
- 凭证:elastic-start-local/.env
认证 — 始终使用API密钥
bash
测试连接
curl -s $ELASTICSEARCH
URL -H Authorization: ApiKey $ELASTICSEARCHAPI_KEY
Python客户端 9.x
from elasticsearch import Elasticsearch
es = Elasticsearch(ES
URL, apikey=API_KEY)
参考文件
仅在需要时加载——不要一次性全部加载:
| 文件 | 何时加载 |
|---|
| references/semantic-search.md | 设置JINA、semantictext、推理端点 |
| references/vector-search.md |
kNN查询、densevector映射、RRF混合搜索 |
| references/classic-patterns.md | 映射设计、布尔查询、聚合、分页 |
| references/python-client-9.md | Python elasticsearch 9.x — 无body=、关键字参数、类型提示 |
何时使用每种模式
用户询问含义/意图/查找类似X的产品
→ semantic_text + 语义查询 → references/semantic-search.md
用户需要精确匹配与语义结合
→ 混合搜索(RRF) → references/vector-search.md
用户询问映射、字段类型、分析器、聚合
→ 经典模式 → references/classic-patterns.md
用户使用Python elasticsearch库
→ 始终检查 → references/python-client-9.md
安全最佳实践
- - 始终使用API密钥而非用户名/密码
- 将API密钥范围限定到特定索引和最小权限
- 对于只读OpenClaw访问:privileges: [read, viewindexmetadata]
- 将凭证存储在.env中,切勿硬编码在脚本中
- .env始终添加到.gitignore
json
POST /security/apikey
{
name: openclaw-readonly,
role_descriptors: {
reader: {
indices: [{ names: [my-index], privileges: [read] }]
}
}
}
// 响应:
{
id: VuaCfGcBCdbkQm-e5aOx,
name: openclaw-readonly,
api_key: ui2lp2axTNmsyakw9tvNnw,
encoded: VnVhQ2ZHY0JDZGJrUW0tZTVhT3g6dWkybHAyYXhUTm1zeWFrdzl0dk5udw==
}
⚠️ 立即保存响应中的encoded字段——之后无法再次获取。
添加到:~/.openclaw/workspace-[name]/.env 作为 ELASTICSEARCHAPIKEY