Skip to main content

Relevance Examples

Start with representative queries and expected results. Apply one tuning change at a time, rerun the same cases, and keep the smallest rule set that works.

Add collection synonyms

Treat laptop, notebook, and portable computer as equivalent product terms:

curl --fail-with-body -X POST \
http://localhost:9200/collections/products/synonyms/portable-computers \
-H "Content-Type: application/json" \
-d '{"synonyms":["laptop","notebook","portable computer"]}'

List and remove the rule:

curl http://localhost:9200/collections/products/synonyms
curl -X DELETE \
http://localhost:9200/collections/products/synonyms/portable-computers

Prefer collection synonyms unless the vocabulary truly applies everywhere.

Remove low-value words

curl --fail-with-body -X POST \
http://localhost:9200/collections/products/stopwords \
-H "Content-Type: application/json" \
-d '{"word":"the"}'

Do not add domain terms merely because they occur frequently; doing so can make valid queries impossible. See Stopwords for local and global scope behavior.

Pin a result for an exact query

curl --fail-with-body -X POST \
http://localhost:9200/collections/products/overrides/featured-keyboard \
-H "Content-Type: application/json" \
-d '{
"rule": {"query":"keyboard","match":"exact"},
"includes": [{"id":"keyboard-2","position":1}]
}'

To suppress a known bad result, use "excludes":["document-id"]. Overrides are best for explicit merchandising or editorial decisions, not broad relevance tuning.

Save reusable search parameters

curl --fail-with-body -X PUT \
http://localhost:9200/presets/storefront-search \
-H "Content-Type: application/json" \
-d '{
"query_by": "title,description,tags",
"facet_by": "category,brand",
"highlight_full_fields": "title",
"limit": 24
}'

curl http://localhost:9200/presets/storefront-search

Presets centralize shared defaults. Keep user input such as q, pagination, and allowed filters separate from the preset unless the application requires fixed values.

Boost important query terms

curl --fail-with-body -X POST \
http://localhost:9200/collections/products/documents/search \
-H "Content-Type: application/json" \
-d '{
"q": "wireless^2 keyboard",
"query_by": "title,description,tags",
"limit": 10
}'

Use moderate boosts and verify that they improve more than one hand-picked query. For custom ranker configuration, see Ranking.

A simple evaluation loop

Keep a small table in version control:

[
{"q":"travel keyboard","expected_top_ids":["keyboard-1"]},
{"q":"gaming keyboard","expected_top_ids":["keyboard-2"]},
{"q":"notebook accessories","expected_top_ids":["stand-1","sleeve-1"]}
]

Run each query before and after a change, compare the first few IDs, and record latency as well as ranking quality. This catches synonym and override changes that fix one query while degrading another.