🗓️ 04102025 0034

ELASTICSEARCH TEXT SEARCH CHEATSHEET

A quick reference for Elasticsearch search capabilities and when to use each type.

Core Concepts​

Full-Text vs Exact Match​

TypeUse CaseExample
Full-TextNatural language search, fuzzy matching"searching for articles"
Exact MatchIDs, status codes, categoriesstatus: "active"

Key difference: Full-text is analyzed (lowercased, stemmed, tokenized), exact match is not.

Search Types Overview​

Search TypeWhat It DoesBest For
MatchFull-text search with analysisGeneral search, user queries
Multi-MatchSearch across multiple fieldsSearching title + description
Match PhraseExact phrase in order"New York", "machine learning"
TermExact value matchIDs, enums, keywords
FuzzyTypo-tolerant searchHandling misspellings
PrefixStarts with...Autocomplete, type-ahead
WildcardPattern matchinguser*, *@gmail.com
RegexpRegex patternsComplex pattern matching
RangeNumeric/date rangesPrice filters, date ranges
BoolCombine queriesComplex filtering logic

match vs term​

  • match: Analyzed (lowercased, stemmed) - "Searching" → "search"
  • term: Exact value - "Searching" ≠ "searching"

match vs match_phrase​

  • match: Words can be in any order
  • match_phrase: Words must be in exact order

must vs filter (in bool)​

  • must: Affects relevance score (use for search)
  • filter: Yes/no match, faster (use for filtering)

should vs must​

  • should: Optional, boosts score if matched (OR logic)
  • must: Required (AND logic)

Common Patterns​

Search with Filters​

Combine search queries (must) with filters (filter) - filters don't affect relevance score and are cached for performance.

Fuzzy Search with Minimum Match​

Use fuzziness: "AUTO" to handle typos, and minimum_should_match (e.g., "75%") to require a percentage of search terms to match.

Pattern matching with * and ? - useful but can be slow, especially with leading wildcards.

Performance Tips​

  1. Use filters over queries when you don't need scoring
  2. Term queries are faster than match queries
  3. Wildcard with * at start is slow - avoid if possible
  4. Use prefix/edge_ngram for autocomplete, not wildcard
  5. Cache filters - ES automatically caches filter results
  6. Limit fields in multi_match - don't search everything

References​