AI Hints
Home›Elasticsearch Tutorial›Custom Scoring and Typos
Elasticsearch · Lesson 66 of 120

Fuzzy Matching

Typos still work.

⏱ 2 min read▶ Video at 1:02:30🎓 Free
Watch this lesson in the Elasticsearch courseWatch on YouTube ↗Full Elasticsearch course

People type fast, and they make typos. Tnet instead of tent. Jakcet instead of jacket. Fuzzy matching finds words that are just one or two letters away.

  • tnet
  • jakcet
  • Close enough

fuzziness: AUTO

We search names for jakcet, with fuzziness set to auto. Auto allows one edit for medium words, and two for long ones. Run it. The jackets are found, despite the typo.

Dev Tools Consoletext
GET products/_search?filter_path=hits.total.value,hits.hits._source.name
{
  "query": { "match": {
    "name": { "query": "jakcet", "fuzziness": "AUTO" } } },
  "size": 3
}
Output
{
  "hits": {
    "total": {"value": 7},
    "hits": [
      {"_source": {"name": "Storm Rain Jacket"}},
      {"_source": {"name": "Breeze Rain Jacket"}},
      {"_source": {"name": "Cloudburst Rain Jacket"}}
    ]
  }
}
Also uses _load
catalog

How fuzzy works

An edit is adding, removing or changing one letter, or swapping two letters next to each other. Auto allows zero edits for very short words, one for three to five letters, and two beyond that. Prefix length keeps the first letters exact, which is faster.

keyvalue
Editadd, remove, change, swap
AUTO0, 1 or 2 edits
prefix_lengthfirst letters exact
Costslower than exact

Summary

Fuzziness auto matches words with small typos. It's a big win for any search box. Next, let's practise better ranking.

Key takeaways
  • fuzziness
  • AUTO
  • Typos OK
Next up: Practice: Better Ranking — put it together