elasticsearch-query-optimization
БесплатноБез исполняемых скриптовНе проверенDiagnose slow Elasticsearch Query DSL searches and propose measured fixes. Use when a search is slow, profile output shows an expensive clause, exact-match…
от elastic★ 615 звёзд на GitHubОб этом скилле
Elasticsearch Query DSL Optimization
Diagnose why a Query DSL search is slow, identify the dominant cost from the profile (not guesswork), rewrite the query to remove that cost while preserving match semantics, and re-measure with profiling enabled.
Environment Configuration
This skill executes Elasticsearch operations through the elastic CLI. If the
elastic CLI is not installed, tell the user what it is needed for. Do
not guess credentials, call the HTTP API directly, or attempt other workarounds.
This skill references operations in HTTP-shorthand form (e.g., GET /, GET /_cat/indices, GET /{index}/_mapping,
GET /{index}/_settings/index.mode, POST /_query). The Operations table at the end of this document
maps each shorthand to the equivalent elastic CLI command — always use the CLI rather than calling the HTTP API
directly.
Scope: Query DSL searches via
POST /{index}/_search. This skill does not migrate queries to ES|QL — it optimizes the existing bool/match/term/wildcard structure the user already runs.Ground rule: Never recommend "add shards" or "scale hardware" as the primary fix when the profile names a specific clause (for example
WildcardQueryat ~3.8s). Fix the query first; infrastructure changes require evidence the query is already optimal.
Process
Confirm connectivity and locate the target index. Call
GET /. If the call fails, stop — do not guess endpoints or credentials. When the user names an index pattern (for examplelogs-*), narrow candidates withGET /_cat/indicesand pick the index or pattern the query actually targets.Decision: proceed only when the index is known. Data needed: index name or pattern, and the slow Query DSL body (from the user or from a saved search).
Profile the slow query to find the dominant cost. Call
POST /{index}/_searchwith"profile": trueand the user's query unchanged. Readtook, then inspectprofile.shards[].searches[].query— sort child collectors bytime_in_nanosand identify the top contributor.Decision: classify the bottleneck from profile evidence:
TermQuery/PointRangeQuery/MatchNoDocsQueryinsidemustalongside a scoring clause — exact-match or range filters are being scored unnecessarily. Likely fix: move them tofiltercontext (step 4a).WildcardQuerywith a leading*(for examplemessage:*timeout*) — cannot use the inverted index; scans terms per document. Likely fix: remove the leading wildcard (step 4b).MatchQueryon atextfield — expected scoring cost; optimize only if profile shows it dominates after filter-context fixes.- High
aggregationtime — separate from query tuning; profile the agg tree (out of scope unless the user asked about aggs).
Data needed: profile tree with
type,description,time_in_nanos, andbreakdown(especiallynext_docfor wildcards). Quote the top contributor verbatim when explaining the diagnosis.Inspect field mappings before rewriting. Call
GET /{index}/_mapping. For every clause you will move or rewrite, confirm the field type:term/terms/filteron exact values — field must bekeyword(or another non-analyzed type). Atermon atextfield is a common bug; if types are wrong, say so and suggest the correct sub-field (for exampleservice.keyword) or a mapping change — do not silently rewrite.match/match_phrase— target atextfield (analyzed).wildcard— works onkeywordorwildcardtypes; leading*still forces a scan regardless of type.
Decision: only propose rewrites that match confirmed types. Data needed: mapping for each field referenced in the query.
Rewrite the query to remove the profiled bottleneck.
4a. Move non-scoring clauses from
musttofilterWhen exact-match
term/terms/range/matchon a keyword (or other non-scoring intent) clauses sit inmustalongside a full-textmatchthat should drive relevance:- Move exact-match clauses into
bool.filter(or afilterarray entry). - Keep only clauses that must affect
_scoreinbool.must(typically the full-textmatch).
Why: filter context skips scoring and participates in the filter/bitset cache on repeated queries. Semantics: the same documents match; only scoring and performance change — state this explicitly.
Example rewrite pattern:
{ "query": { "bool": { "filter": [{ "term": { "status": "active" } }, { "term": { "tenant_id": "acme" } }], "must": [{ "match": { "description": "wireless keyboard" } }] } } }4b. Eliminate leading wildcards
When the profile shows `Wildcar
- Move exact-match clauses into
Установить elasticsearch-query-optimization в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл elasticsearch-query-optimization?
Diagnose slow Elasticsearch Query DSL searches and propose measured fixes. Use when a search is slow, profile output shows an expensive clause, exact-match filters sit in scoring context, or leading wildcards dominate latency. Ground every recommendation in search profiling — move non-scoring clauses to filter context, eliminate leading wildcards, and re-profile to confirm improvement.
Как установить скилл elasticsearch-query-optimization?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл elasticsearch-query-optimization запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
agent-skill-stack
Find, evaluate, and assemble the smallest compatible set of AI Agent Skills for an end-to-end natural-language goal. Use when a user wants Skills for a…
от GitHubbuild-evidence-map
Build an auditable evidence map for a contested technical choice, research synthesis, proposal review, or consequential decision. Use when Copilot must…
от GitHubpinecone-rag
Build production RAG pipelines and persistent agent memory using Pinecone as the vector database backend. ALWAYS USE THIS SKILL when the user mentions…
от GitHubqdrant-monitoring-debugging
Diagnoses Qdrant production issues using metrics and observability tools. Use when someone reports 'optimizer stuck', 'indexing too slow', 'memory too high'…
от GitHub