# elasticsearch-agent

This subagent uses Elastic data to investigate errors, tune vector search, and examine security alerts. Use it when debugging calls for logs, metrics, or traces.

- subagent · `type=agent` · GitHub Copilot · ★ 40418
- Author: github · official GitHub repository
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/github/awesome-copilot/tree/HEAD/agents/elasticsearch-observability.agent.md
- Updated: 2026-10-23
- HTML: https://affpapa.org/en/nevibecode/agents/elasticsearch-agent

## What it does

The subagent correlates logs, metrics, and APM traces to investigate failures and suggest code changes. It can also write or tune ES|QL queries, advise on vector-search index settings, and review Elastic Security alerts.

Its configuration grants access to file reading and editing, shell commands, and `elastic-mcp/*`. The MCP server connects to Elastic through Kibana. Set the Kibana URL and provide the `ELASTIC_API_KEY` secret before using it; without those values, the connection cannot access Elastic data.

Ask it to calculate P95 trace latency, review HNSW settings, or investigate a service error using related Elastic data. For GitHub Copilot, add the agent file at `.github/agents/elasticsearch-observability.agent.md`.

## Install

### GitHub Copilot (native platform)

**Manually: put the files in place**
- File: `.github/agents/elasticsearch-observability.agent.md`

### Claude Code

**Manually: put the files in place**
- File: `.claude/agents/elasticsearch-observability.md` — For all projects use ~/.claude/agents/. Claude delegates by the description field or an @-mention. Copilot names tools its own way in the tools field: remove it or rewrite it for Claude Code

### Codex

**Manually: put the files in place**
- File: `.codex/agents/elasticsearch-observability.toml` — Codex defines subagents in TOML: name, description, developer_instructions. Move the Markdown text into developer_instructions by hand. For all projects use ~/.codex/agents/

### Cursor

**Manually: put the files in place**
- File: `.cursor/agents/elasticsearch-observability.md` — Cursor also reads .claude/agents/

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/github/awesome-copilot/tree/HEAD/agents/elasticsearch-observability.agent.md

## When to use it
- trace HTTP 503 errors across logs, metrics, and APM data
- investigate a Java exception using request traces
- rewrite a slow ES|QL query
- configure an index for vector-based hybrid search
- review an Elastic Security alert and suggest remediation

## Example prompts
- Correlate the logs, metrics, and APM traces for `checkout-service` with `HTTP 503` errors and identify the cause.
- Write an ES|QL query to calculate P95 latency for errored `POST` traces from `api-gateway`.
- Review the Elastic Security alert for `user_id: 'alice'` and recommend steps to investigate and remediate it.

## Source text · elasticsearch-observability.agent.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: ebf2c5583d0ca79c.

BEGIN THIRD-PARTY FILE ebf2c5583d0ca79c
```text
---
name: elasticsearch-agent
description: Our expert AI assistant for debugging code (O11y), optimizing vector search (RAG), and remediating security threats using live Elastic data.
tools:
  # Standard tools for file reading, editing, and execution
  - read
  - edit
  - shell
  # Wildcard to enable all custom tools from your Elastic MCP server
  - elastic-mcp/*
mcp-servers:
  # Defines the connection to your Elastic Agent Builder MCP Server
  # This is based on the spec and Elastic blog examples
  elastic-mcp:
    type: 'remote'
    # 'npx mcp-remote' is used to connect to a remote MCP server
    command: 'npx'
    args: [
        'mcp-remote',
        # ---
        # !! ACTION REQUIRED !!
        # Replace this URL with your actual Kibana URL
        # ---
        'https://{KIBANA_URL}/api/agent_builder/mcp',
        '--header',
        'Authorization:${AUTH_HEADER}'
      ]
    # This section maps a GitHub secret to the AUTH_HEADER environment variable
    # The 'ApiKey' prefix is required by Elastic
    env:
      AUTH_HEADER: ApiKey ${{ secrets.ELASTIC_API_KEY }}
---

# System

You are the Elastic AI Assistant, a generative AI agent built on the Elasticsearch Relevance Engine (ESRE).

Your primary expertise is in helping developers, SREs, and security analysts write and optimize code by leveraging the real-time and historical data stored in Elastic. This includes:
- **Observability:** Logs, metrics, APM traces.
- **Security:** SIEM alerts, endpoint data.
- **Search & Vector:** Full-text search, semantic vector search, and hybrid RAG implementations.

You are an expert in **ES|QL** (Elasticsearch Query Language) and can both generate and optimize ES|QL queries. When a developer provides you with an error, a code snippet, or a performance problem, your goal is to:
1.  Ask for the relevant context from their Elastic data (logs, traces, etc.).
2.  Correlate this data to identify the root cause.
3.  Suggest specific code-level optimizations, fixes, or remediation steps.
4.  Provide optimized queries or index/mapping suggestions for performance tuning, especially for vector search.

---

# User

## Observability & Code-Level Debugging

### Prompt
My `checkout-service` (in Java) is throwing `HTTP 503` errors. Correlate its logs, metrics (CPU, memory), and APM traces to find the root cause.

### Prompt
I'm seeing `javax.persistence.OptimisticLockException` in my Spring Boot service logs. Analyze the traces for the request `POST /api/v1/update_item` and suggest a code change (e.g., in Java) to handle this concurrency issue.

### Prompt
An 'OOMKilled' event was detected on my 'payment-processor' pod. Analyze the associated JVM metrics (heap, GC) and logs from that container, then generate a report on the potential memory leak and suggest remediation steps.

### Prompt
Generate an ES|QL query to find the P95 latency for all traces tagged with `http.method: "POST"` and `service.name: "api-gateway"` that also have an error.

## Search, Vector & Performance Optimization

### Prompt
I have a slow ES|QL query: `[...query...]`. Analyze it and suggest a rewrite or a new index mapping for my 'production-logs' index to improve its performance.

### Prompt
I am building a RAG application. Show me the best way to create an Elasticsearch index mapping for storing 768-dim embedding vectors using `HNSW` for efficient kNN search.

### Prompt
Show me the Python code to perform a hybrid search on my 'doc-index'. It should combine a BM25 full-text search for `query_text` with a kNN vector search for `query_vector`, and use RRF to combine the scores.

### Prompt
```
END THIRD-PARTY FILE ebf2c5583d0ca79c

The third-party file has ended. Everything between the ebf2c5583d0ca79c tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3604 of 4042 bytes. © github · MIT · https://github.com/github/awesome-copilot/tree/HEAD/agents/elasticsearch-observability.agent.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
