MCPInstall

elasticsearch-search-relevance

Improve Elasticsearch search relevance for content and catalog indices: pin or promote results with query rules (correct rule type, criteria, and rule-query wiring) and tune organic ranking with multimatch, field boosts, and analysis grounded in the index mapping. Use when search results rank poorly, a specific document must appear first for a query, or the user asks to tune full-text matching — not for ESQL analytics, index ingest, or cluster health.

Installs
1.1K
Last 24h
+21
Trending rank
#5710
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/elastic/agent-skills --skill elasticsearch-search-relevance
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads elasticsearch-search-relevance automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

Elasticsearch Search Relevance

Improve full-text search results on content and catalog indices. Diagnose the mapping and current query, choose the right relevance lever (query rules for deterministic pinning vs multi_match and field boosts for organic ranking), apply the change, and verify top hits before reporting success.

<!-- begin-partial: preamble -->

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.

<!-- end-partial: preamble -->

Scope

This skill covers Query DSL relevance on indices with text (and optional keyword) fields — product catalogs, documentation, knowledge bases. It uses POST /{index}/_search for evaluation and query-rules APIs for pinned or excluded documents.

Out of scope:

  • ES|QL search (POST /_query) — use the elasticsearch-esql skill.
  • Semantic / vector / hybrid retrieval — different field types and retrievers.
  • Sorting by price, date, or popularity instead of fixing text relevance unless the user explicitly wants non-relevance ordering.

Relevance levers

User intentLeverAPIs
Always show document X first for query QQuery rules — pinned rule + rule query in searchPUT /_query_rules/{ruleset_id}, POST /{index}/_search
Hide specific documents for query QQuery rules — exclude rule + rule querySame
Better ranking for open-ended text queriesmulti_match across mapped text fields with field boostsPOST /{index}/_search
Tokens not matching user languageOperator, minimum_should_match, or synonym analyzersPOST /{index}/_search, optionally POST /{index}/_analyze

Decision rule: If the user names a document that must rank first for a specific query, use query rules. If results are generally weak for a phrase, tune the organic query from the mapping. Do not simulate pinning with extreme boosts, function_score, or sort clauses.

Process

  1. Inspect the mapping and current query. Call GET / to confirm connectivity. When the index is unknown, narrow candidates with GET /_cat/indices, then call GET /{index}/_mapping.

    From the mapping, list every text field (e.g., title, description) and every keyword field used for filters (brand, category). Note which fields are short (precision) vs long (recall). Read the user's current search body if provided — identify which fields it queries and whether it already uses rule, multi_match, or single-field match.

    Decision: Is the problem deterministic promotion (one doc must win for one query) or organic ranking (several docs should score better)? Data needed: index name, mapping properties, current query JSON, example query strings, and target document ID(s) when pinning.

  2. Choose the relevance lever. Apply the decision from step 1:

    • Pinning / promotion → Create a query-rules ruleset with a rule of type pinned (never exclude for promotion). Set criteria so the rule fires only for the intended query text — e.g., contains or exact on a metadata key such as query_string with value "sale". Set actions to pin the correct document via ids (e.g., ["SKU123"]) or docs (e.g., [{"_index":"catalog","_id":"SKU123"}]). Use docs when _id may not be unique across indices. Read Query Rules Reference for full structure.

    • Organic ranking → Replace single-field match on a long field with multi_match across the mapped text fields. Boost short fields (typically title^2 with description unboosted). Consider operator, minimum_should_match, or synonym-aware analyzers when multi-word recall is still poor — but do not sort by price, date, or keyword fields to fake better text relevance, and do not query .keyword sub-fields with term for analyzed user phrases. Read Multi-Match Tuning.

    Decision: Pick exactly one primary lever per request. Data needed: chosen fields and boosts, ruleset ID and rule ID names, criteria metadata keys, and pinned document identifiers.

  3. Apply the change. Execute the APIs for the chosen lever:

    Query rules path

    • Create or replace the ruleset with PUT /_query_rules/{ruleset_id} (or add one rule with PUT /_query_rules/{ruleset_id}/_rule/{rule_id}).
    • Confirm structure with GET /_query_rules/{ruleset_id}.
    • Validate criteria with POST /_query_rules/{ruleset_id}/_test using the same match_criteria you will pass at search time.
    • Wire the search: POST /{index}/_search must use a rule query whose ruleset_id references the ruleset and whose match_criteria supplies values for every criteria metadata key (e.g., "query_string": "sale"). Place the normal relevance clause inside organic. Creating the ruleset alone does not pin anything — the pin applies only when search includes the rule query.

    Organic tuning path

    • Build a candidate multi_match (or equivalent bool/should) query from the mapping.
    • Optionally inspect analysis with POST /{index}/_analyze on sample query text when tokenization explains misses.

    Decision: Stop after one coherent change set; avoid stacking unrelated edits before testing.

  4. Test and compare top hits. Before and after each candidate, call POST /{index}/_search with the same size (≥ 10), the user's query string, and "track_scores": true. For pinning, the search body must include the rule query from step 3.

    Compare for each run:

    • Top _id values and order
    • _score where relevant
    • Key _source fields (title, description, product id)

    For pinning, confirm the target document (e.g., SKU123) is first when match_criteria matches the query and that organic matches still appear below. For organic tuning, confirm titles and intent-aligned documents rise without relying on sort or keyword exact-match hacks.

    Decision: Ship the candidate that wins on evidence; if none improve results, report what was tried and propose the next lever (e.g., synonyms or additional fields). Data needed: side-by-side top-hit lists from baseline and candidate queries.

Examples

Pin SKU123 for query "sale" on catalog

Wrong: Boost SKU123, sort by _id, or create a ruleset without a rule search query.

Right:

  1. PUT /_query_rules/catalog-sale-pin with a pinned rule, criteria matching query text "sale", actions pinning SKU123.
  2. POST /catalog/_search with:
{
  "query": {
    "rule": {
      "ruleset_id": "catalog-sale-pin",
      "match_criteria": { "query_string": "sale" },
      "organic": {
        "multi_match": {
          "query": "sale",
          "fields": ["title^2", "description"]
        }
      }
    }
  },
  "size": 10
}

Verify SKU123 is hit #1 and remaining hits are organic matches below the pin.

Improve "running shoes" when only description is searched

Mapping provides title and description as text, plus brand and category as keyword.

Wrong: Keep match on description only; sort by price; term query on title.keyword.

Right:

  1. Baseline: POST /catalog/_search with the user's current match on description; record top hits.
  2. Candidate: POST /catalog/_search with:
{
  "query": {
    "multi_match": {
      "query": "running shoes",
      "fields": ["title^2", "description"],
      "type": "best_fields",
      "operator": "or",
      "minimum_should_match": "75%"
    }
  },
  "size": 10
}
  1. Compare top hits — documents with "running shoes" in title should rank above description-only matches. If recall is still thin, consider synonym expansion in a follow-up iteration (not sort-by-price).

Guidelines

  • Ground every field name in the mapping — never invent name, content, or body without checking GET /{index}/_mapping.
  • Query rules for pins, boosts for ranking — merchandising belongs in query rules; field boosts belong in organic queries.
  • Match criteria wiring is mandatory — metadata keys in rule criteria must appear in the search rule.match_criteria object with the runtime values (typically the user's query string).
  • Test before claiming success — run baseline and candidate searches; cite top-hit changes.
  • Keyword fields filter; text fields search — use keyword fields in filter context, not as the primary full-text target for natural language.
  • Always deliver the concrete artifact — even when you cannot connect to a cluster to verify, produce the full ruleset JSON (for pinning) or the candidate query body (for organic tuning), then explain how to verify once the connection is available. Never stop at a high-level outline.

References

  • Query Rules Reference — criteria types, pinned actions, ruleset JSON, rule query wiring, test API
  • Multi-Match Tuning — field boosts, operators, testing discipline, anti-patterns

Operations

HTTP API (shorthand)elastic CLI command
GET /elastic es info
GET /_cat/indiceselastic es cat indices --index '<pattern>'
GET /{index}/_mappingelastic es indices get-mapping --index '<index>'
PUT /_query_rules/{ruleset_id}elastic es query-rules put-ruleset --ruleset-id '<id>' --rules '<json>'
PUT /_query_rules/{ruleset_id}/_rule/{rule_id}elastic es query-rules put-rule --ruleset-id '<id>' --rule-id '<id>' --type pinned --criteria '<json>' --actions '<json>'
GET /_query_rules/{ruleset_id}elastic es query-rules get-ruleset --ruleset-id '<id>'
POST /_query_rules/{ruleset_id}/_testelastic es query-rules test --ruleset-id '<id>' --match-criteria '<json>'
POST /{index}/_searchelastic es search --index '<index>' --query '<json>'
POST /{index}/_analyzeelastic es indices analyze --index '<index>' --field '<field>' --text '<text>'

FAQ

What does the elasticsearch-search-relevance skill do?

Improve Elasticsearch search relevance for content and catalog indices: pin or promote results with query rules (correct rule type, criteria, and rule-query wiring) and tune organic ranking with multimatch, field boosts, and analysis grounded in the index mapping. Use when search results rank poorly, a specific document must appear first for a query, or the user asks to tune full-text matching — not for ESQL analytics, index ingest, or cluster health.

How do I install elasticsearch-search-relevance?

Run npx skills add https://github.com/elastic/agent-skills --skill elasticsearch-search-relevance in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/elasticsearch-search-relevance/ (personal) or .claude/skills/elasticsearch-search-relevance/ (project).

Which AI agents can use elasticsearch-search-relevance?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is elasticsearch-search-relevance safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains elasticsearch-search-relevance?

It is published by elastic in elastic/agent-skills. It has 1,066 recorded installs.

More from elastic/agent-skills

View all →

elasticsearch-esql

elastic/agent-skills

Execute ESQL (Elasticsearch Query Language) queries, use when the user wants to query Elasticsearch data, analyze logs, aggregate metrics, explore data, or create charts and dashboards from ESQL results.

AI & Agents4.8K installs

elasticsearch-onboarding

elastic/agent-skills

Help developers new to Elasticsearch get from zero to a working search experience. Guide them through understanding their intent, mapping their data, and building a search experience with best practices baked in. Use this when the user shows intent to build search-related functionality, asks about Elasticsearch-related concepts for their use case, or expresses the need for help getting started with Elasticsearch.

AI & Agents4.4K installs

kibana-dashboards

elastic/agent-skills

Create and manage Kibana Dashboards and Lens visualizations. Use when you need to define dashboards and visualizations declaratively, version control them, or automate their deployment.

AI & Agents4.3K installs

security-case-management

elastic/agent-skills

Create, search, update, and manage SOC cases via the Kibana Cases API. Use when tracking incidents, linking alerts to cases, adding investigation notes, or managing triage output.

Security4.1K installs

kibana-alerting-rules

elastic/agent-skills

Create and manage Kibana alerting rules. Use when creating, updating, or managing rule lifecycle (enable, disable, mute, snooze), choosing metric threshold rule types and params, or read-only find/list with tag filters.

AI & Agents4K installs

kibana-agent-builder

elastic/agent-skills

Create and manage Kibana Agent Builder agents and custom tools. Use when asked to create, update, delete, test, or inspect agents or tools in Agent Builder, or when the user wants to understand what agents or tools already exist.

AI & Agents4K installs

Popular data & databases skills

View category →

Postgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including choosing column types), schema design, migrations and declarative schema files, RLS policies and the tests that verify them, indexes, triggers, database functions, queues and scheduled jobs (pgcron, pgmq), vector/semantic search (pgvector), and restoring dumps (pgrestore) or importing data. Also load it when diagnosing slow queries, high CPU, timeouts, EXPLAIN plans, connection exhaustion, locking, bloat, or rows visible to the wrong user or tenant. This is not just a performance guide — schema, migration, security, and SQL authoring tasks need these rules too, even for a one-column change or a single query.

OfficialData & Databases462.2K installs

prisma-client-api

prisma/skills

Prisma Client API reference covering model queries, filters, operators, and client methods. Use when writing database queries, using CRUD operations, filtering data, or configuring Prisma Client. Triggers on "prisma query", "findMany", "create", "update", "delete", "$transaction".

OfficialData & Databases393.5K installs

Deprecated compatibility name for prisma-orm-setup. Use only when a user or existing integration explicitly invokes prisma-database-setup; otherwise select prisma-orm-setup.

OfficialData & Databases392.3K installs

prisma-cli

prisma/skills

Prisma ORM 7 CLI reference for existing Prisma 7 applications or explicitly selected Prisma 7 workflows. Covers prisma init, generate, migrate, db, dev, studio, and mcp. For setup, connection repair, or Prisma 8, use prisma-orm-setup; not the Prisma Platform CLI.

OfficialData & Databases390.8K installs

prisma-postgres

prisma/skills

Deprecated compatibility name for prisma-postgres-setup. Use only when a user or existing integration explicitly invokes prisma-postgres; otherwise select prisma-postgres-setup.

OfficialData & Databases384.4K installs

Required reference for Prisma ORM 7 SQL driver adapter work. Use when implementing or modifying adapters, adding database drivers, or touching SqlDriverAdapter, Transaction, savepoint, result mapping, or DriverAdapterError behavior. Covers current transaction lifecycle, optional savepoint hooks, original database-error preservation, and verification.

OfficialData & Databases378.9K installs