PrepZone Logo
PrepZone

Full-Text Search Queries

match, bool, fuzzy, and term queries for product search that tolerates typos.

Why this matters

  • VaultCommerce search must tolerate typos (backpak), boost title matches over description, and filter by category without affecting score.
  • Using match on a keyword field or term on analyzed text silently returns wrong results — the #1 Elasticsearch bug in production.
  • Relevance tuning (boost, minimum_should_match, fuzziness) directly impacts conversion rate.
Cluster
Node 1Shard 0 primary
Node 2Shard 1 primary
Node 3Shard 0 replica
An index is split into shards across nodes. Replicas provide failover and read scaling.

match: analyzed full-text

Java
GET /vaultcommerce-products/_search
{
  "query": {
    "match": {
      "title": {
        "query": "trail pack waterproof",
        "operator": "and"
      }
    }
  }
}

The analyzer tokenizes input the same way it tokenized indexed text — lowercase, stemming optional, stop words removed per analyzer config.

bool: filter + must + should

Java
GET /vaultcommerce-products/_search
{
  "query": {
    "bool": {
      "must": [
        { "match": { "description": { "query": "hiking gear", "fuzziness": "AUTO" } } }
      ],
      "filter": [
        { "term": { "category": "outdoor" } },
        { "range": { "price": { "lte": 100 } } },
        { "term": { "in_stock": true } }
      ],
      "should": [
        { "match": { "title": { "query": "trail", "boost": 3 } } }
      ],
      "minimum_should_match": 0
    }
  }
}

Bool clause roles

  • must — scored required clauses (contribute to relevance).
  • filter — yes/no constraints cached without scoring (category, price range).
  • should — optional boosts; use minimum_should_match when they become required.
  • must_not — exclusion filters (hide discontinued SKUs).

Filters run in filter context — faster and cacheable. VaultCommerce category sidebar uses filter clauses exclusively.

Term-level queries on keywords

Java
GET /vaultcommerce-products/_search
{
  "query": {
    "term": { "sku": "SKU-8842" }
  }
}

GET /vaultcommerce-products/_search
{
  "query": {
    "terms": { "tags": ["hiking", "camping"] }
  }
}

Never term-query analyzed text — use match or a .raw keyword sub-field.

Multi-match and autocomplete

Java
GET /vaultcommerce-products/_search
{
  "query": {
    "multi_match": {
      "query": "summit tent",
      "fields": ["title^3", "description", "tags^2"],
      "type": "best_fields",
      "fuzziness": "AUTO"
    }
  }
}

Prefix and match_phrase_prefix power typeahead — at scale, switch to edge n-gram analyzers at index time (covered in production ops).

Quick recall

Everything you need if you only revisit this box.

  • match for analyzed text; term/terms for keyword fields.
  • bool combines must (scored), filter (not scored), should (boost), must_not.
  • Filters are cacheable — use for category, price, stock constraints.
  • multi_match with field boosts weights title over description.
  • Fuzziness AUTO tolerates typos on customer search boxes.
  • VaultCommerce never term-queries analyzed description text.

Test yourself

Answer these before moving on — recall is what makes it stick.