Elasticsearch can support full-text search, filtering, and relevance tuning across a content corpus. It also introduces an index lifecycle, mappings, synchronization, and operational costs. Start with the search behavior users need and compare it with the database search already available.
Model searchable documents
Define one document shape per content type with a stable ID, canonical route, title, excerpt, body, tags, publication state, and timestamps. Map fields deliberately: analyzed text for natural-language search, keyword fields for exact filters, and dates for sorting. Keep code identifiers searchable without applying transformations that destroy punctuation users rely on.
Only index content that is public and published. Remove or update documents when visibility changes, and plan for stale results if synchronization is asynchronous. A transactional outbox or change stream can help, but the source database remains authoritative. Avoid sending private fields to the index even if queries later filter them out.
Tune with real queries
Use representative searches to adjust boosts for titles, tags, and body mentions. Measure zero-result rates, clicked results, reformulations, latency, and index lag. Synonyms and fuzziness can improve recall but may make exact technical terms less precise.
Test index rebuilds, mapping changes, deletes, and recovery from failed updates. Elasticsearch is justified when measured search requirements exceed a simpler solution; using a search cluster is not itself evidence of better search.
Make relevance and visibility separate checks
Elasticsearch's match query analyzes input text before querying a mapped field. A match against a title can therefore behave differently from an exact term query against a keyword field. Map title and body fields for the language and ranking needs of developer content, and use a boolean filter for structured publication state. Elasticsearch match query
A publication update can commit before its search document is refreshed or reindexed. Keep the database as the source of truth for the final visibility check, and test a user unpublishing a result that is still present in search. Evaluate relevance with known query and expected-title pairs. Record what happens to abbreviations, dotted identifiers, titles, and misspellings before changing analyzers or boosting fields. The search index helps find candidates while permission checks decide which candidates a reader can see.
Worked example
This Elasticsearch query sketch assumes those indexed fields and mappings. Recheck database visibility before returning hydrated hits so stale index state cannot expose a newly private article.
json{ "query": { "bool": { "must": [{ "match": { "title": "draft recovery" } }], "filter": [{ "term": { "isPublished": true } }, { "term": { "visibility": "public" } }] } } }




Community
Discussion
Loading comments…