Loading...
Loading...
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 multi_match, 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 ES|QL analytics, index ingest, or cluster health.
npx skill4agent add elastic/agent-skills elasticsearch-search-relevanceelasticelasticGET /GET /_cat/indicesGET /{index}/_mappingGET /{index}/_settings/index.modePOST /_queryelastictextkeywordPOST /{index}/_searchPOST /_queryelasticsearch-esql| User intent | Lever | APIs |
|---|---|---|
| Always show document X first for query Q | Query rules — | |
| Hide specific documents for query Q | Query rules — | Same |
| Better ranking for open-ended text queries | | |
| Tokens not matching user language | Operator, | |
function_scoreGET /GET /_cat/indicesGET /{index}/_mappingtexttitledescriptionkeywordbrandcategoryrulemulti_matchmatchpinnedexcludecriteriacontainsexactquery_string"sale"actionsids["SKU123"]docs[{"_index":"catalog","_id":"SKU123"}]docs_idmatchmulti_matchtexttitle^2descriptionoperatorminimum_should_match.keywordtermPUT /_query_rules/{ruleset_id}PUT /_query_rules/{ruleset_id}/_rule/{rule_id}GET /_query_rules/{ruleset_id}POST /_query_rules/{ruleset_id}/_testmatch_criteriaPOST /{index}/_searchruleruleset_idmatch_criteriametadata"query_string": "sale"organicrulemulti_matchPOST /{index}/_analyzePOST /{index}/_searchsize"track_scores": truerule_id_score_sourcetitledescriptionSKU123match_criteriacatalogSKU123_idrulePUT /_query_rules/catalog-sale-pinpinned"sale"SKU123POST /catalog/_search{
"query": {
"rule": {
"ruleset_id": "catalog-sale-pin",
"match_criteria": { "query_string": "sale" },
"organic": {
"multi_match": {
"query": "sale",
"fields": ["title^2", "description"]
}
}
}
},
"size": 10
}SKU123descriptiontitledescriptiontextbrandcategorykeywordmatchdescriptiontermtitle.keywordPOST /catalog/_searchmatchdescriptionPOST /catalog/_search{
"query": {
"multi_match": {
"query": "running shoes",
"fields": ["title^2", "description"],
"type": "best_fields",
"operator": "or",
"minimum_should_match": "75%"
}
},
"size": 10
}titlenamecontentbodyGET /{index}/_mappingmetadatarule.match_criteriakeywordfilterpinnedrule| HTTP API (shorthand) | |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |