elasticsearch
它能做什么
这个技能指导 Elasticsearch 相关工作,包括查询语法、字段映射、聚合和集群健康。适合构建搜索功能,或分析日志和时间序列数据的人。
适用场景
- ✓当你需要在 Elasticsearch 中编写搜索查询或筛选结果时。
- ✓当你在把数据加载到 Elasticsearch 之前设计索引映射时。
- ✓当集群显示黄色或红色健康状态,需要排查时。
技能链接
https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/elasticsearch/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请编写一个 Elasticsearch 查询,找出过去 24 小时内的错误日志,并按服务名称统计数量。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能推荐显式的映射、清晰的查询结构和聚合,并给出检查集群健康和分片大小的步骤。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Elasticsearch Expert
A search and analytics specialist with deep expertise in Elasticsearch cluster architecture, query DSL, mapping design, and performance optimization. This skill provides production-grade guidance for building search experiences, log analytics pipelines, and time-series data platforms using the Elastic stack.
Key Principles
- Design mappings explicitly before indexing data; relying on dynamic mapping leads to field type conflicts and bloated indices
- Understand the difference between keyword fields (exact match, aggregations, sorting) and text fields (full-text search with analyzers)
- Use index aliases for zero-downtime reindexing, canary deployments, and time-based index rotation
- Size shards between 10-50 GB for optimal performance; too many small shards waste overhead, too few large shards limit parallelism
- Monitor cluster health (green/yellow/red) continuously and investigate yellow status immediately, as it indicates unassigned replica shards
Techniques
- Construct bool queries with must (scored AND), filter (unscored AND), should (OR with minimum_should_match), and must_not (exclusion) clauses
- Use match queries for full-text search with analyzer-aware tokenization, and term queries for exact keyword lookups without analysis
- Build aggregations: terms for top-N cardinality, date_histogram for time bucketing, nested for sub-document analysis, and pipeline aggs like cumulative_sum
- Apply Index Lifecycle Management (ILM) policies with hot/warm/cold/delete phases to automate rollover and data retention
- Reindex with POST _reindex using source/dest, applying scripts for field transformations during migration
- Check cluster allocation with GET _cluster/allocation/explain to diagnose why shards remain unassigned
- Tune search performance with the search profiler API, request caching, and pre-warming for frequently used queries
Common Patterns
- Search-as-you-type: Use the search_as_you_type field type or edge_ngram tokenizer with a match_phrase_prefix query for autocomplete experiences
- Parent-Child Relationships: Use join field types for one-to-many relationships where child documents update independently, avoiding costly nested reindexing
- Cross-cluster Search: Configure remote clusters and use cluster:index syntax to query across multiple Elasticsearch deployments transparently
- Snapshot and Restore: Register a snapshot repository (S3, GCS, or filesystem) and schedule regular snapshots for disaster recovery with SLM policies
Pitfalls to Avoid
- Do not use wildcard queries on text fields with leading wildcards, as they bypass the inverted index and cause full field scans
- Do not index large documents (over 100 MB) without splitting them; they cause memory pressure during indexing and merging
- Do not set number_of_replicas to 0 in production; replicas provide both search throughput and data redundancy
- Do not update mappings on existing indices for incompatible type changes; create a new index with the correct mapping and reindex the data
常见问题
为什么要自己定义映射?
依赖自动映射可能导致字段类型冲突和索引膨胀,因此该技能推荐显式映射。
黄色集群状态是什么意思?
该技能说明,黄色通常表示副本分片未被分配,应立即排查。
keyword 字段和 text 字段有什么区别?
keyword 字段匹配精确值并支持排序,而 text 字段会被分词,用于全文搜索。
详情
作者的原始描述
Elasticsearch expert for queries, mappings, aggregations, index management, and cluster operations
repo: RightNow-AI/openfang
热度
- GitHub 星标
- 18k
- 排名
- #10675
- 许可证
- Apache-2.0
- 更新时间
- 2026/7/2
评论
- …
同一仓库的更多技能
browser-automation
18k教你的智能体使用 Playwright 控制网页浏览器,借助 CSS 选择器找到按钮、表单和链接。
clip-hand-skill
18k帮你的智能体制作视频片段:下载视频、转录语音、生成字幕文件,并用 ffmpeg 剪辑片段。
collector-hand-skill
18k帮你的智能体收集某个主题或公司的公开信息,提取关键实体,跟踪变化并判断舆论倾向。
infisical-sync-skill
18k帮你的智能体通过 API 读取和更新 Infisical 保险库中的密钥,包含登录步骤和清晰的错误处理。