Fuzzy matching helps find words that are close to what you typed, even if there are small mistakes or typos.
Fuzzy matching in Elasticsearch
{
"query": {
"fuzzy": {
"field_name": {
"value": "search_term",
"fuzziness": "AUTO",
"prefix_length": 1
}
}
}
}fuzziness controls how many changes (like letter swaps or missing letters) are allowed.
prefix_length means how many letters at the start must match exactly.
name field for words like "jon", "john", or "jonh".{
"query": {
"fuzzy": {
"name": {
"value": "jon",
"fuzziness": "AUTO"
}
}
}
}{
"query": {
"fuzzy": {
"city": {
"value": "bostn",
"fuzziness": 2,
"prefix_length": 2
}
}
}
}This query searches the product_name field for terms similar to "iphon", like "iphone" or "iphonr". It helps find products even if the user misspells the name.
{
"query": {
"fuzzy": {
"product_name": {
"value": "iphon",
"fuzziness": "AUTO",
"prefix_length": 1
}
}
}
}Fuzzy matching can slow down searches if used on large data without limits.
Use prefix_length to improve performance by requiring some exact matches at the start.
Fuzziness set to AUTO lets Elasticsearch decide the best number of allowed changes based on word length.
Fuzzy matching helps find words that are close to the search term, fixing small typos.
It uses fuzziness to control how many letter changes are allowed.
Setting prefix_length improves speed by requiring some exact letters at the start.