- What is the difference between a query context and a filter context?
- Query context (must, should) calculates a relevance score for each matching document. Filter context (filter, must_not) only determines yes/no match without scoring — it is faster and cached. Use filter context for exact-match conditions (date ranges, status fields) and query context for full-text search.
- What is an inverted index?
- An inverted index maps each unique term to the list of documents containing it — the reverse of a document-to-content index. This enables O(1) lookup of which documents contain a search term, making full-text search fast. Lucene (and Elasticsearch) use inverted indexes as their core data structure.
- When should I use Elasticsearch vs PostgreSQL full-text search?
- Elasticsearch handles large-scale search (millions of documents), complex relevance tuning, distributed search across shards, and analytics aggregations. PostgreSQL full-text search (tsvector) is sufficient for small-medium datasets and avoids operational complexity. Choose based on scale and feature requirements.