# Fuzziness & score computation

**URL:** https://discuss.elastic.co/t/fuzziness-score-computation/16492
**Category:** Elasticsearch
**Created:** [March 20, 2014, 9:46am UTC](https://discuss.elastic.co/t/fuzziness-score-computation/16492 "2014-03-20T09:46:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Adrian\_Luna](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@Adrian\_Luna](https://discuss.elastic.co/u/Adrian_Luna)
#### Post date: [March 20, 2014, 9:46am UTC](https://discuss.elastic.co/t/fuzziness-score-computation/16492/1 "2014-03-20T09:46:49Z")

</div>

Hi,

Sorry that I am relatively fresh to elasticsearch so please don't be too  
harsh.

I feel like I'm not being able to understand the behaviour of any of the  
fuzzy queries in ES.

_1) match with fuzziness enabled_

{  
"query": {  
"fuzzy\_like\_this\_field": {  
"field\_name": {  
"like\_text": "car renting London",  
"fuzziness": "0.5"  
}  
}  
}  
}

As I see it from my tests, this kind of query will give same score to  
documents with field\_name="car renting London" and "car ranting London" or  
"car renting Londen" for example. That means, it will not give any  
negatively score misspellings. I can imagine that first the possible  
variants are computed and then the score is just computed with a  
"representative score" which is the same for every variant that match the  
requirements.

Am I right? If I am, is it any way to boost the exact match over the fuzzy  
match?

Also I get results with more terms getting the same score, like "cheap car  
renting London", "offers car renting London". That's something I cannot get  
to understand. When I use the explain API, it seems that the resulting  
score is a sum of the different matches with its internal weightings,  
tf-idf, etc. but it seems to not be considering the terms outside the  
query, while I would expect the exact match to score at least slightly  
higher.

Am I missing something here? Is it just the expected result and I am just  
being too demanding?

_2) fuzzy query_

That doesn't make what I want since it does not analyze the query (I think)  
and so it will treat the query in an unexpected way for my purposes of  
"free text" search

_3) fuzzy\_like\_this or fuzzy\_like\_this\_field_

This other search takes rid of the first problem in point 1, since as I  
read from the documentation, it seems to use some tricks to avoid favouring  
rare terms (misspellings will be here) over more frequent terms, etc. but  
it's still giving the same score to exact match and matches where other  
terms are present.

Is there any way to get the expected behaviour?. By this I mean to be able  
to execute almost free-text queries with some fuzziness to take rid of  
possible misspellings in the query terms, but with an (at least for me)  
more exhaustive score computation. If not, is there any other more complex  
query or a function\_score to get such a performance.

Thank you very much, any comment will be pretty much appreciated. Also, if  
I am not right in my suppositions, any clarification will be very welcome.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/916f5408-ecfd-4676-8d48-db4467a9d839%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/916f5408-ecfd-4676-8d48-db4467a9d839%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)
#### Post date: [March 20, 2014, 2:02pm UTC](https://discuss.elastic.co/t/fuzziness-score-computation/16492/2 "2014-03-20T14:02:39Z")

</div>

You are correct in your analysis of the fuzzy scoring. Fuzzy variants are  
scored (relatively) the same as the exact match, because they are treated  
the same when executed internally.

If you want to score exact matches higher, I would use a boolean  
combination of an exact match and a fuzzy match. Semi-pseudo-query here:

{  
"query": {  
"bool": {  
"should": [  
{  
"match" : {  
"my\_field" : {  
"query" : "car renting london",  
"operator" : "and"  
},  
"boost" : 2  
}  
},  
{  
"fuzzy\_like\_this": {}  
}  
]  
}  
}  
}

Basically, the match query is set to AND operator (so all terms are  
required) and it is given a boost of 2. That means that exact matches will  
be boosted preferentially over the fuzzy matches, which will have the  
default boost of 1.

Also I get results with more terms getting the same score, like "cheap car

> renting London", "offers car renting London".

The reason you are seeing results like this is because you are using the  
fuzzy\_like\_this query. It's a combination of more\_like\_this and fuzzy.  
The way MLT works is that it takes all the individual terms in your query,  
builds a big boolean and searches the index for the boolean. Docs just  
need the terms, in no particular order. The Fuzzy Like This works the  
same, except terms are allowed to fuzzily match. With MLT and FLT, you're  
bound to find "off-target" results because these queries are sorta like  
shotguns, looking for a wide spread of terms.

_2) fuzzy query_

> That doesn't make what I want since it does not analyze the query (I  
> think) and so it will treat the query in an unexpected way for my purposes  
> of "free text" search

As an alternative, you can use the Match query and set the "fuzziness"  
parameter. You'll get fuzzy like the fuzzy query, but analysis from the  
Match query.

As a general comment, trying to deal with misspellings and fuzziness is  
always a game between precision (number of returned results that are  
correct) and recall (number of correct results that are returned). As you  
increase fuzziness, you increase recall -- more of your correct results are  
in your search hits...but you lose precision...they may be at position 200.  
You'll always be battling the precision/recall fight.

I would instead search for exact matches, and prompt user to fix  
mispellings with suggesters. This makes your search and relevancy _vastly_ simpler,  
and tends to provide a better user experience because they can just click  
the as-you-type suggestion or the "Did you mean?" link. Win win for  
everyone.

-Zach

On Thursday, March 20, 2014 4:46:49 AM UTC-5, Adrian Luna wrote:

> Hi,
> 
> Sorry that I am relatively fresh to elasticsearch so please don't be too  
> harsh.
> 
> I feel like I'm not being able to understand the behaviour of any of the  
> fuzzy queries in ES.
> 
> _1) match with fuzziness enabled_
> 
> {  
> "query": {  
> "fuzzy\_like\_this\_field": {  
> "field\_name": {  
> "like\_text": "car renting London",  
> "fuzziness": "0.5"  
> }  
> }  
> }  
> }
> 
> As I see it from my tests, this kind of query will give same score to  
> documents with field\_name="car renting London" and "car ranting London" or  
> "car renting Londen" for example. That means, it will not give any  
> negatively score misspellings. I can imagine that first the possible  
> variants are computed and then the score is just computed with a  
> "representative score" which is the same for every variant that match the  
> requirements.
> 
> Am I right? If I am, is it any way to boost the exact match over the fuzzy  
> match?
> 
> Also I get results with more terms getting the same score, like "cheap car  
> renting London", "offers car renting London". That's something I cannot get  
> to understand. When I use the explain API, it seems that the resulting  
> score is a sum of the different matches with its internal weightings,  
> tf-idf, etc. but it seems to not be considering the terms outside the  
> query, while I would expect the exact match to score at least slightly  
> higher.
> 
> Am I missing something here? Is it just the expected result and I am just  
> being too demanding?
> 
> _2) fuzzy query_
> 
> That doesn't make what I want since it does not analyze the query (I  
> think) and so it will treat the query in an unexpected way for my purposes  
> of "free text" search
> 
> _3) fuzzy\_like\_this or fuzzy\_like\_this\_field_
> 
> This other search takes rid of the first problem in point 1, since as I  
> read from the documentation, it seems to use some tricks to avoid favouring  
> rare terms (misspellings will be here) over more frequent terms, etc. but  
> it's still giving the same score to exact match and matches where other  
> terms are present.
> 
> Is there any way to get the expected behaviour?. By this I mean to be able  
> to execute almost free-text queries with some fuzziness to take rid of  
> possible misspellings in the query terms, but with an (at least for me)  
> more exhaustive score computation. If not, is there any other more complex  
> query or a function\_score to get such a performance.
> 
> Thank you very much, any comment will be pretty much appreciated. Also, if  
> I am not right in my suppositions, any clarification will be very welcome.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a8e3e438-9d27-449f-81c2-b50907dcd184%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a8e3e438-9d27-449f-81c2-b50907dcd184%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:41am UTC](https://discuss.elastic.co/t/fuzziness-score-computation/16492/3 "2017-07-06T01:41:51Z")

</div>


