Elasticsearch Fuzzy Search
Fuzzy search matches typos and misspellings: "elasticsearch" matches "elasti*searh", "elastikserch".
Fuzzy Query
GET /products/_search
{
"query": {
"fuzzy": {
"name": {
"value": "elasticsearch",
"fuzziness": "AUTO", // auto-tune based on term length
"max_expansions": 50,
"prefix_length": 0 // 0 = allow prefix fuzzyness too
}
}
}
}
fuzziness values:
-
0- exact match only -
1- 1 edit distance (delete, insert, or substitute) -
2- 2 edit distances -
AUTO- adjusts based on term length (0-2)
Match Query with Fuzziness
GET /articles/_search
{
"query": {
"match": {
"title": {
"query": "databse design",
"fuzziness": "1",
"operator": "and" // all terms must match
}
}
}
}
Combined: Fuzzy + Synonym + Language
PUT /documents
{
"settings": {
"analysis": {
"filter": {
"my_synonyms": {
"type": "synonym",
"synonyms": ["db => database", "elasticsearch => es"]
}
},
"analyzer": {
"my_search_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": ["lowercase", "my_synonyms"]
}
}
}
},
"mappings": {
"properties": {
"content": {
"type": "text",
"analyzer": "my_search_analyzer"
}
}
}
}
GET /documents/_search
{
"query": {
"match": {
"content": {
"query": "databse",
"fuzziness": "AUTO"
}
}
}
}
// Matches: "database", "databases", "db"







