# Fuzzy searches not matching as expected

**URL:** <https://discuss.elastic.co/t/fuzzy-searches-not-matching-as-expected/14018>\
**Category:** Elasticsearch\
**Created:** [October 18, 2013, 4:03pm UTC](https://discuss.elastic.co/t/fuzzy-searches-not-matching-as-expected/14018 "2013-10-18T16:03:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![designermonkey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/designermonkey/32/2035_2.png) [@designermonkey](https://discuss.elastic.co/u/designermonkey)\
**Post date:** [October 18, 2013, 4:03pm UTC](https://discuss.elastic.co/t/fuzzy-searches-not-matching-as-expected/14018/1 "2013-10-18T16:03:16Z")

</div>

I have a search set up to do fuzzy matching on the tokens that the standard  
analyzer returns.

It all works well on single words, and we get accurate results, say, on a  
title field like 'Cherry Cheesecake'. If we search for either 'Cherry', or  
'Cheesecake' we get a result.

If we search for 'Cherry Cheesecake' we get 0 results.

I'm really at a loss as to how this can be happening, as I would have  
thought it matches closer than either separate word.

The index is as follows:

{  
"analysis": {  
"analyzer": {  
"custom\_fulltext" : {  
"type": "custom",  
"tokenizer" : "standard",  
"filter": ["stop", "asciifolding", "snowball", "lowercase",  
"custom\_synonyms", "custom\_stop"]  
}  
},  
"filter" : {  
"custom\_synonyms": {  
"type": "synonym",  
"ignore\_case": "true",  
"synonyms": [  
"i-pod, i pod =\> ipod",  
"definately, definitly, definetly =\> definitely"  
]  
},  
"custom\_stop": {  
"type": "stop",  
"stopwords": ["a", "an", "and", "are", "as", "at", "be", "but", "by",  
"into", "is", "it", "of", "on", "or", "such", "that", "the", "their",  
"there", "these", "they", "this", "to", "was", "will"]  
}  
}  
}  
}

The mapping is as such:

{  
"recipes": {  
"properties": {  
"title": {  
"type": "string",  
"index": "analyzed",  
"analyzer": "nigella\_fulltext"  
},  
"url": {  
"type": "string",  
"index": "no",  
"include\_in\_all": false  
},  
"introduction": {  
"type": "string",  
"index": "no",  
"include\_in\_all": false  
},  
"ingredients": {  
"type": "string",  
"index": "analyzed"  
},  
"moods": {  
"type": "string",  
"index": "not\_analyzed",  
"include\_in\_all": false  
},  
"occasions": {  
"type": "string",  
"index": "not\_analyzed",  
"include\_in\_all": false  
},  
"is\_vegetarian": {  
"type": "string",  
"store": "yes",  
"index": "not\_analyzed",  
"null\_value": "no"  
},  
"is\_gluten\_free": {  
"type": "string",  
"store": "yes",  
"index": "not\_analyzed",  
"null\_value": "no"  
},  
"is\_express": {  
"type": "string",  
"store": "yes",  
"index": "not\_analyzed",  
"null\_value": "no"  
},  
"is\_baking": {  
"type": "string",  
"store": "yes",  
"index": "not\_analyzed",  
"null\_value": "no"  
}  
"is\_premium": {  
"type": "string",  
"store": "yes",  
"index": "not\_analyzed",  
"null\_value": "no"  
},  
"ordering\_field": {  
"type": "integer",  
"store": "yes",  
"index": "not\_analyzed",  
"null\_value": "0"  
}  
}  
}  
}

And the search is as follows:

{  
"explain": true,  
"sort": [{  
"ordering\_field": "desc"  
}, "\_score"],  
"size": 15,  
"from": 0,  
"query": {  
"bool": {  
"should": [{  
"bool": {  
"should": [{  
"fuzzy": {  
"recipes.title": {  
"value": "cherry cheesecake",  
"min\_similarity": 0.75,  
"boost": 5  
}  
}  
}, {  
"fuzzy": {  
"recipes.ingredients": {  
"value": "cherry cheesecake",  
"min\_similarity": 0.75  
}  
}  
}, ]  
}  
}]  
}  
},  
"facets": {  
"filtered\_sections": {  
"terms": {  
"field": "\_type"  
}  
},  
"is\_express": {  
"terms": {  
"field": "recipes.is\_express"  
}  
},  
"is\_vegetarian": {  
"terms": {  
"field": "recipes.is\_vegetarian"  
}  
},  
"mood": {  
"terms": {  
"field": "recipes.moods"  
}  
},  
"occasion": {  
"terms": {  
"field": "recipes.occasions"  
}  
}  
},  
"filter": [{  
"terms": {  
"\_type": ["recipes"]  
}  
}]  
}

I've been tearing my hair out to this point to get search returning any  
kind of accurate results, anf this is the first time I have good results,  
but then find out that it doesn't even work for a perfect match.

Any help anyone has would be greatly appreciated.

John.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [October 18, 2013, 5:05pm UTC](https://discuss.elastic.co/t/fuzzy-searches-not-matching-as-expected/14018/2 "2013-10-18T17:05:54Z")

</div>

Hi John

The `fuzzy` query is a term-based query, not a full text query, so it is  
looking for a _single_ term that is fuzzily like "cherry cheesecake".

Change to using the `match` or `multi_match` query instead:

{  
"multi\_match": {  
"fields": [  
"recipes.title",  
"recipes.ingredients"  
],  
"query": "cherry cheesecake",  
"fuzziness": 2  
}  
}

clint

On 18 October 2013 18:03, John Porter [john@designermonkey.co.uk](mailto:john@designermonkey.co.uk) wrote:

> I have a search set up to do fuzzy matching on the tokens that the  
> standard analyzer returns.
> 
> It all works well on single words, and we get accurate results, say, on a  
> title field like 'Cherry Cheesecake'. If we search for either 'Cherry', or  
> 'Cheesecake' we get a result.
> 
> If we search for 'Cherry Cheesecake' we get 0 results.
> 
> I'm really at a loss as to how this can be happening, as I would have  
> thought it matches closer than either separate word.
> 
> The index is as follows:
> 
> {  
> "analysis": {  
> "analyzer": {  
> "custom\_fulltext" : {  
> "type": "custom",  
> "tokenizer" : "standard",  
> "filter": ["stop", "asciifolding", "snowball", "lowercase",  
> "custom\_synonyms", "custom\_stop"]  
> }  
> },  
> "filter" : {  
> "custom\_synonyms": {  
> "type": "synonym",  
> "ignore\_case": "true",  
> "synonyms": [  
> "i-pod, i pod =\> ipod",  
> "definately, definitly, definetly =\> definitely"  
> ]  
> },  
> "custom\_stop": {  
> "type": "stop",  
> "stopwords": ["a", "an", "and", "are", "as", "at", "be", "but", "by",  
> "into", "is", "it", "of", "on", "or", "such", "that", "the", "their",  
> "there", "these", "they", "this", "to", "was", "will"]  
> }  
> }  
> }  
> }
> 
> The mapping is as such:
> 
> {  
> "recipes": {  
> "properties": {  
> "title": {  
> "type": "string",  
> "index": "analyzed",  
> "analyzer": "nigella\_fulltext"  
> },  
> "url": {  
> "type": "string",  
> "index": "no",  
> "include\_in\_all": false  
> },  
> "introduction": {  
> "type": "string",  
> "index": "no",  
> "include\_in\_all": false  
> },  
> "ingredients": {  
> "type": "string",  
> "index": "analyzed"  
> },  
> "moods": {  
> "type": "string",  
> "index": "not\_analyzed",  
> "include\_in\_all": false  
> },  
> "occasions": {  
> "type": "string",  
> "index": "not\_analyzed",  
> "include\_in\_all": false  
> },  
> "is\_vegetarian": {  
> "type": "string",  
> "store": "yes",  
> "index": "not\_analyzed",  
> "null\_value": "no"  
> },  
> "is\_gluten\_free": {  
> "type": "string",  
> "store": "yes",  
> "index": "not\_analyzed",  
> "null\_value": "no"  
> },  
> "is\_express": {  
> "type": "string",  
> "store": "yes",  
> "index": "not\_analyzed",  
> "null\_value": "no"  
> },  
> "is\_baking": {  
> "type": "string",  
> "store": "yes",  
> "index": "not\_analyzed",  
> "null\_value": "no"  
> }  
> "is\_premium": {  
> "type": "string",  
> "store": "yes",  
> "index": "not\_analyzed",  
> "null\_value": "no"  
> },  
> "ordering\_field": {  
> "type": "integer",  
> "store": "yes",  
> "index": "not\_analyzed",  
> "null\_value": "0"  
> }  
> }  
> }  
> }
> 
> And the search is as follows:
> 
> {  
> "explain": true,  
> "sort": [{  
> "ordering\_field": "desc"  
> }, "\_score"],  
> "size": 15,  
> "from": 0,  
> "query": {  
> "bool": {  
> "should": [{  
> "bool": {  
> "should": [{  
> "fuzzy": {  
> "recipes.title": {  
> "value": "cherry cheesecake",  
> "min\_similarity": 0.75,  
> "boost": 5  
> }  
> }  
> }, {  
> "fuzzy": {  
> "recipes.ingredients": {  
> "value": "cherry cheesecake",  
> "min\_similarity": 0.75  
> }  
> }  
> }, ]  
> }  
> }]  
> }  
> },  
> "facets": {  
> "filtered\_sections": {  
> "terms": {  
> "field": "\_type"  
> }  
> },  
> "is\_express": {  
> "terms": {  
> "field": "recipes.is\_express"  
> }  
> },  
> "is\_vegetarian": {  
> "terms": {  
> "field": "recipes.is\_vegetarian"  
> }  
> },  
> "mood": {  
> "terms": {  
> "field": "recipes.moods"  
> }  
> },  
> "occasion": {  
> "terms": {  
> "field": "recipes.occasions"  
> }  
> }  
> },  
> "filter": [{  
> "terms": {  
> "\_type": ["recipes"]  
> }  
> }]  
> }
> 
> I've been tearing my hair out to this point to get search returning any  
> kind of accurate results, anf this is the first time I have good results,  
> but then find out that it doesn't even work for a perfect match.
> 
> Any help anyone has would be greatly appreciated.
> 
> John.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![designermonkey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/designermonkey/32/2035_2.png) [@designermonkey](https://discuss.elastic.co/u/designermonkey)\
**Post date:** [October 18, 2013, 9:25pm UTC](https://discuss.elastic.co/t/fuzzy-searches-not-matching-as-expected/14018/3 "2013-10-18T21:25:32Z")

</div>

Hi Clint,

Thanks for responding, I think I see what you mean.

I also think I've got more accurate results using a 'text' query with  
'fuzziness' for the search, and I'm wondering if I need to add the fuzzy  
queries as well to match the single words?

Also, can you boost a specific field in a text query at search time?

On Friday, 18 October 2013 18:05:54 UTC+1, Clinton Gormley wrote:

> Hi John
> 
> The `fuzzy` query is a term-based query, not a full text query, so it is  
> looking for a _single_ term that is fuzzily like "cherry cheesecake".
> 
> Change to using the `match` or `multi_match` query instead:
> 
> {  
> "multi\_match": {  
> "fields": [  
> "recipes.title",  
> "recipes.ingredients"  
> ],  
> "query": "cherry cheesecake",  
> "fuzziness": 2  
> }  
> }
> 
> clint
> 
> On 18 October 2013 18:03, John Porter \<[jo...@designermonkey.co.uk](mailto:jo...@designermonkey.co.uk)\<javascript:\>
> 
> > wrote:
> 
> > I have a search set up to do fuzzy matching on the tokens that the  
> > standard analyzer returns.
> > 
> > It all works well on single words, and we get accurate results, say, on a  
> > title field like 'Cherry Cheesecake'. If we search for either 'Cherry', or  
> > 'Cheesecake' we get a result.
> > 
> > If we search for 'Cherry Cheesecake' we get 0 results.
> > 
> > I'm really at a loss as to how this can be happening, as I would have  
> > thought it matches closer than either separate word.
> > 
> > The index is as follows:
> > 
> > {  
> > "analysis": {  
> > "analyzer": {  
> > "custom\_fulltext" : {  
> > "type": "custom",  
> > "tokenizer" : "standard",  
> > "filter": ["stop", "asciifolding", "snowball", "lowercase",  
> > "custom\_synonyms", "custom\_stop"]  
> > }  
> > },  
> > "filter" : {  
> > "custom\_synonyms": {  
> > "type": "synonym",  
> > "ignore\_case": "true",  
> > "synonyms": [  
> > "i-pod, i pod =\> ipod",  
> > "definately, definitly, definetly =\> definitely"  
> > ]  
> > },  
> > "custom\_stop": {  
> > "type": "stop",  
> > "stopwords": ["a", "an", "and", "are", "as", "at", "be", "but", "by",  
> > "into", "is", "it", "of", "on", "or", "such", "that", "the", "their",  
> > "there", "these", "they", "this", "to", "was", "will"]  
> > }  
> > }  
> > }  
> > }
> > 
> > The mapping is as such:
> > 
> > {  
> > "recipes": {  
> > "properties": {  
> > "title": {  
> > "type": "string",  
> > "index": "analyzed",  
> > "analyzer": "nigella\_fulltext"  
> > },  
> > "url": {  
> > "type": "string",  
> > "index": "no",  
> > "include\_in\_all": false  
> > },  
> > "introduction": {  
> > "type": "string",  
> > "index": "no",  
> > "include\_in\_all": false  
> > },  
> > "ingredients": {  
> > "type": "string",  
> > "index": "analyzed"  
> > },  
> > "moods": {  
> > "type": "string",  
> > "index": "not\_analyzed",  
> > "include\_in\_all": false  
> > },  
> > "occasions": {  
> > "type": "string",  
> > "index": "not\_analyzed",  
> > "include\_in\_all": false  
> > },  
> > "is\_vegetarian": {  
> > "type": "string",  
> > "store": "yes",  
> > "index": "not\_analyzed",  
> > "null\_value": "no"  
> > },  
> > "is\_gluten\_free": {  
> > "type": "string",  
> > "store": "yes",  
> > "index": "not\_analyzed",  
> > "null\_value": "no"  
> > },  
> > "is\_express": {  
> > "type": "string",  
> > "store": "yes",  
> > "index": "not\_analyzed",  
> > "null\_value": "no"  
> > },  
> > "is\_baking": {  
> > "type": "string",  
> > "store": "yes",  
> > "index": "not\_analyzed",  
> > "null\_value": "no"  
> > }  
> > "is\_premium": {  
> > "type": "string",  
> > "store": "yes",  
> > "index": "not\_analyzed",  
> > "null\_value": "no"  
> > },  
> > "ordering\_field": {  
> > "type": "integer",  
> > "store": "yes",  
> > "index": "not\_analyzed",  
> > "null\_value": "0"  
> > }  
> > }  
> > }  
> > }
> > 
> > And the search is as follows:
> > 
> > {  
> > "explain": true,  
> > "sort": [{  
> > "ordering\_field": "desc"  
> > }, "\_score"],  
> > "size": 15,  
> > "from": 0,  
> > "query": {  
> > "bool": {  
> > "should": [{  
> > "bool": {  
> > "should": [{  
> > "fuzzy": {  
> > "recipes.title": {  
> > "value": "cherry cheesecake",  
> > "min\_similarity": 0.75,  
> > "boost": 5  
> > }  
> > }  
> > }, {  
> > "fuzzy": {  
> > "recipes.ingredients": {  
> > "value": "cherry cheesecake",  
> > "min\_similarity": 0.75  
> > }  
> > }  
> > }, ]  
> > }  
> > }]  
> > }  
> > },  
> > "facets": {  
> > "filtered\_sections": {  
> > "terms": {  
> > "field": "\_type"  
> > }  
> > },  
> > "is\_express": {  
> > "terms": {  
> > "field": "recipes.is\_express"  
> > }  
> > },  
> > "is\_vegetarian": {  
> > "terms": {  
> > "field": "recipes.is\_vegetarian"  
> > }  
> > },  
> > "mood": {  
> > "terms": {  
> > "field": "recipes.moods"  
> > }  
> > },  
> > "occasion": {  
> > "terms": {  
> > "field": "recipes.occasions"  
> > }  
> > }  
> > },  
> > "filter": [{  
> > "terms": {  
> > "\_type": ["recipes"]  
> > }  
> > }]  
> > }
> > 
> > I've been tearing my hair out to this point to get search returning any  
> > kind of accurate results, anf this is the first time I have good results,  
> > but then find out that it doesn't even work for a perfect match.
> > 
> > Any help anyone has would be greatly appreciated.
> > 
> > John.
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:11am UTC](https://discuss.elastic.co/t/fuzzy-searches-not-matching-as-expected/14018/4 "2017-07-06T02:11:41Z")

</div>


