Match query slower because it applies text analysis to query string before searching inverted index, while term query performs direct literal lookup without preprocessing. Analysis phase adds measurable overhead: (1) Tokenization - breaking query into tokens based on tokenizer rules (standard tokenizer splits on whitespace/punctuation), (2) Lowercasing - normalizing case ("GET" → "get", "Running" → "running"), (3) Token filtering - removing stopwords ("the", "is", "and"), applying stemming ("running" → "run", "foxes" → "fox"), expanding synonyms ("laptop" → ["laptop", "notebook", "computer"]). Multi-step analysis adds 1-5ms latency per query. Term query skips all analysis: uses query string exactly as provided, single direct index lookup (~<1ms), binary match without relevance scoring. Analysis complexity varies - custom tokenizers, multiple filters, synonym expansion can add 2-10ms.
Elasticsearch Match Vs Term Query FAQ & Answers
4 expert Elasticsearch Match Vs Term Query answers researched from official documentation. Every answer cites authoritative sources you can verify.
unknown
4 questionsPerformance measurements: term query ~2-3ms average latency, match query 3-5ms for typical single-field queries. Absolute difference is milliseconds (2-3ms overhead), but matters at scale - high-volume perspective (10,000 queries/sec) multiplies by query volume. Gap widens with complex analyzers - custom tokenizers, multiple filters, synonym expansion can add 2-10ms total. However, for most applications, 2-5ms difference is negligible compared to network latency (20-100ms) and other processing. Critical consideration: match query enables relevance scoring and fuzzy matching which term query cannot provide. Performance optimization: use filter context instead of query context for term queries to leverage segment-level caching (2-10x faster than query context, skips scoring entirely). Cached term queries can be <1ms.
Use match query for: full-text search on text fields (product descriptions, article content, user input where analysis improves matching). Match analyzes user input matching it against similarly-analyzed indexed terms - "Running shoes" query analyzes to ["run", "shoe"] tokens matching indexed documents containing those stems. Enables fuzzy matching, relevance scoring, synonym expansion. Use term query for: exact matching on keyword fields (UUIDs, status values like "ACTIVE", category IDs, email addresses where analysis would break matching). Term searches unanalyzed keyword fields - query "[email protected]" must match exactly, not tokenized into ["user", "example", "com"]. Critical rule: Always match query type to field type - text fields require match (or multi_match, match_phrase), keyword fields use term (or terms). Field mapping determines indexed form - text fields store analyzed tokens, keyword fields store exact values.
Critical mistake: Using term query on text fields causes mismatches because text fields store analyzed tokens while term query searches for literal strings. Example: Query "Running shoes" on text field searches for exact phrase token "Running shoes", finds nothing because indexed text contains ["run", "shoe"] tokens separately (lowercased and stemmed during indexing). Text field analysis breaks "Running shoes" into tokens during indexing, but term query bypasses analysis during search - mismatch. Solution: (1) Use match query on text fields (applies same analysis to query and indexed content), or (2) Map field as keyword type for exact matching needs. Best practice (2025): For performance-critical exact matching, map as keyword type enabling efficient term queries. Use filter context for term queries to leverage segment-level caching (2-10x faster, skips scoring): {"query": {"bool": {"filter": [{"term": {"status": "ACTIVE"}}]}}}.