es-analytics

Elasticsearch / SLS 只读数据分析:索引探索、mapping、聚合统计、日志搜索、时间序列、多 Profile。

5 stars

Best use case

es-analytics is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Elasticsearch / SLS 只读数据分析:索引探索、mapping、聚合统计、日志搜索、时间序列、多 Profile。

Teams using es-analytics should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/es-analytics/SKILL.md --create-dirs "https://raw.githubusercontent.com/northseadl/norix-skills/main/es-analytics/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/es-analytics/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How es-analytics Compares

Feature / Agentes-analyticsStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Elasticsearch / SLS 只读数据分析:索引探索、mapping、聚合统计、日志搜索、时间序列、多 Profile。

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# ES 数据分析技能

## 零依赖

仅使用 Python 3 标准库(`urllib` + `json`),不需要安装任何第三方包。

## 配置

### 添加连接

```bash
./es config add <profile-name> \
  --url <ES基础URL> \
  --user <用户名/AccessID> \
  --password <密码/AccessSecret> \
  [--default-index <默认索引名>] \
  [--sls]  \
  --test
```

`--sls` 标记该连接为阿里云 SLS ES 兼容端点。SLS 端点有以下行为差异,技能会自动处理:
- **默认只查最近 24h**:所有查询自动注入全时间范围 `range` 条件(除非用户已指定)
- **嵌套字段无法聚合**:`terms` 等聚合作用于未建索引的嵌套字段会报 `sls_field_index_not_configed`
- **`_source` 过滤不可靠**:部分嵌套字段在 `_source` 过滤后丢失

凭据存储在 `~/.agents/data/es-analytics/profiles.json`(权限 `0600`),支持多 Profile。

### 管理连接

```bash
./es config list                    # 列出所有 profile
./es config use <profile-name>      # 切换默认 profile
./es config test [profile-name]     # 测试连接
./es config remove <profile-name>   # 删除 profile
```

## 脚本

### query — ES 查询(只读)

```bash
./es query '{"size":10,"query":{"match_all":{}}}'
./es query -i my-index '{"size":5,"sort":[{"@timestamp":"desc"}]}'
./es query -p prod -i logs '{"query":{"match":{"level":"ERROR"}}}'
./es query --format csv '{"size":50,"query":{"term":{"status":"200"}}}'
```

选项:`-p` profile / `-i` 索引 / `--format table|csv|json` / `--full-range`(SLS 自动全时间范围)

### indices — 索引列表

```bash
./es indices                        # 列出所有索引
./es indices -p prod                # 指定 profile
./es indices --filter "chat*"       # 过滤索引名
```

### mapping — 查看索引 Mapping

```bash
./es mapping my-index               # 查看字段定义
./es mapping my-index -p prod       # 指定 profile
```

### count — 文档计数

```bash
./es count my-index                             # 总数
./es count my-index '{"query":{"match":{"level":"ERROR"}}}'   # 按条件计数
./es count my-index --full-range                # SLS 全时间范围计数
```

### extract — 全量去重提取(search_after 分页)

```bash
./es extract my-index --field auth_id                              # 提取去重字段
./es extract my-index --field auth_id --filter '{"match":{"auth_type":"user"}}'
./es extract my-index --field auth_id --full-range -o /tmp/uids.csv
```

高效分页提取指定字段的唯一值,自动 search_after,适合大数据量去重场景。

### sample — 采样数据

```bash
./es sample my-index                # 最新 5 条数据,展示字段结构
./es sample my-index -n 10 -p prod  # 指定数量和 profile
```

## SLS ES 兼容层注意事项

技能已内建以下保护机制:
1. SLS profile 的查询自动注入 `range` 条件覆盖全时间范围(可通过 `--no-full-range` 禁用)
2. 当聚合收到 `sls_field_index_not_configed` 错误时,自动降级为 search_after 分页 + Python 侧聚合
3. 不依赖 `_source` 过滤功能

## 安全策略

- **只读**: 拦截 DELETE / PUT(非 _search) / POST(非 _search/_count/_mapping)
- **行数限制**: query 默认添加 `size: 200`
- **凭据安全**: 配置文件权限 `0600`,密码不出现在命令行输出

## 模块架构

```
es (Bash CLI 入口)
│
├── config    → config.py     多 Profile 连接管理 (add/list/use/test/remove)
├── query     → query.py      ES 只读查询 (table/csv/json 输出)
├── indices   → indices.py    索引列表
├── mapping   → mapping.py    Mapping 查看
├── count     → count.py      文档计数
├── extract   → extract.py    全量去重提取 (search_after)
└── sample    → sample.py     采样数据
               ↓
            es_core.py         核心引擎 (HTTP 连接 + 安全 + 输出格式化)
               ↓
         ~/.agents/data/es-analytics/
           └── profiles.json   连接配置
```

Related Skills

web-scraper

5
from northseadl/norix-skills

Web scraper with SPA/JavaScript rendering, page interaction, and JS execution. Two-tier engine (HTTP → Playwright browser). Smart discovery, batch fetch, interactive content extraction, OpenAPI parsing. Use when read_url_content fails, SPA rendering needed, or page interaction required.

pm-toolkit

5
from northseadl/norix-skills

自然语言 → Mermaid 图表(16 种)+ 网页原型,本地 Web 面板实时预览/导出。

mobile-testing

5
from northseadl/norix-skills

Android/iOS automated testing: device management, app install, performance profiling, log analysis, screenshot comparison, Maestro E2E orchestration.

llm-agent-dev

5
from northseadl/norix-skills

LLM Agent engineering: pattern selection (12-mode matrix), data simulation, convergence iteration. Covers intent routing, function calling, ReAct, MCP, prompt chaining, guardrails, evaluation.

image-studio

5
from northseadl/norix-skills

AI image generation and editing: e-commerce templates (hero/banner/detail/lifestyle), image refinement (background replace/remove, enhance, retouch, style transfer), icon extraction (bg-removal + detect + smart crop with transparent output).

feishu-integration

5
from northseadl/norix-skills

Feishu (Lark) unified CLI for tasks, documents, wiki, bitable, messaging, approval, and Drive. Supports search/create/edit/publish/export across all modules. Use when reading/writing Feishu docs, searching docs or wiki, managing tasks, sending messages, creating approvals, exporting to Markdown, or any 飞书/Lark interaction.

doc-sentinel

5
from northseadl/norix-skills

Document-code change notification system: traceable doc-code binding via git tree hash, git-diff-driven reconciliation plans with confidence/risk metadata, and idempotent execution. Use when maintaining documentation freshness, detecting stale docs, or binding docs to source code.

coding-net-integration

5
from northseadl/norix-skills

Coding.net DevOps automation: MR lifecycle, CI operations (trigger/logs/stop), artifact registry, cross-project queries, remote file audit.

cnb-cool-integration

5
from northseadl/norix-skills

针对 cnb.cool 的云原生构建(CNB Build):生成/修改 .cnb.yml 流水线、触发规则、 构建环境、runner 资源、缓存、环境变量、手动触发与调试。 在接入、迁移、优化或排查 CNB 构建配置时使用。

agent-task-orchestration

5
from northseadl/norix-skills

Task decomposition and multi-agent orchestration with retry, checkpoint recovery, and real-time monitoring. Mixed Codex/Claude Code engine. Parallel/sequential execution.

agent-swe-team

5
from northseadl/norix-skills

Multi-agent SWE team built on the Workshop model. Full-stack vertical workers, meeting room with @mention notification, private pipes, shared task board. Git worktree isolation, Leader-driven coordination. Mixed Codex/Claude Code engine. Use when a task needs engineering depth beyond a single agent. NOT for simple task parallelism (use agent-task-orchestration) or design discussions (use agent-brainstorm).

agent-front-design

5
from northseadl/norix-skills

Frontend design blueprints with craftsmanship scoring, self-critique loops, and engineering handoff. Aesthetic intelligence against AI homogeneity. Use for: UI/UX design specs, design system creation, visual direction exploration, component design review, design-to-engineering handoff.