# Questions about Fuzzy Query

**URL:** <https://discuss.elastic.co/t/questions-about-fuzzy-query/7467>\
**Category:** Elasticsearch\
**Created:** [April 26, 2012, 1:16am UTC](https://discuss.elastic.co/t/questions-about-fuzzy-query/7467 "2012-04-26T01:16:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![A\_dit\_rien](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@A\_dit\_rien](https://discuss.elastic.co/u/A_dit_rien)\
**Post date:** [April 26, 2012, 1:16am UTC](https://discuss.elastic.co/t/questions-about-fuzzy-query/7467/1 "2012-04-26T01:16:07Z")

</div>

Hi guys,

I am brand new to ElasticSearch, and am currently exploring its  
features. One of them I am interested in is the fuzzy query, which I  
am testing and having troubles to use. It is probably a dummy question  
so I guess someone who already used this feature will quickly find the  
answer, at least I hope. 🙂

Actually I already posted this message on StackOverflow but didn't get  
any answer yet. If you want to take a look, this is the web page:

> <https://stackoverflow.com/questions/10309199/elasticsearchs-fuzzy-query>

BTW I have the feeling that it might not be only related to  
ElasticSearch but maybe directly to Lucene.

Let's start with a new index named "first index" in which I store an  
object "label" with value "american football". This is the query I  
use.

bash-3.2$ curl -XPOST '[http://localhost:9200/firstindex/node/](http://localhost:9200/firstindex/node/)?  
pretty=true' -d '{ "node" : {  
"label" : "american football"  
}  
}  
'

This is the result I get.

{  
"ok" : true,  
"\_index" : "firstindex",  
"\_type" : "node",  
"\_id" : "6TXNrLSESYepXPpFWjpl1A",  
"\_version" : 1  
}

So far so good, now I want to find this entry using a fuzzy query.  
This is the one I send:

bash-3.2$ curl -XGET '[http://localhost:9200/firstindex/node/\_search](http://localhost:9200/firstindex/node/_search)?  
pretty=true' -d ' {"query" : {  
"fuzzy" : {  
"label" : {  
"value" : "american football",  
"boost" : 1.0,  
"min\_similarity" : 0.0,  
"prefix\_length" : 0  
}  
}  
}  
}  
'

And this is the result I get

{  
"took" : 15,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" : []  
}  
}

As you can see, no hit. But now, when I shrink a bit my query's value  
from "american football" to "american footb" like this:

bash-3.2$ curl -XGET '[http://localhost:9200/firstindex/node/\_search](http://localhost:9200/firstindex/node/_search)?  
pretty=true' -d ' {"query" : {  
"fuzzy" : {  
"label" : {  
"value" : "american footb",  
"boost" : 1.0,  
"min\_similarity" : 0.0,  
"prefix\_length" : 0  
}  
}  
}  
}  
'

Then I get a correct hit on my entry, thus the result is:

{ "took" : 0,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 0.19178301,  
"hits" : [ {  
"\_index" : "firstindex",  
"\_type" : "node",  
"\_id" : "6TXNrLSESYepXPpFWjpl1A",  
"\_score" : 0.19178301, "\_source" : {  
"node" : {  
"label" : "american football"  
}  
}  
} ]  
}  
}

So, I have several questions related to this test:

1. Why I didn't get any result when performing a query with a value  
completely equals the my only entry "american football"

2. Is it related to the fact that I have a multi-words value?

3. Is there a way to get the "similarity" score in my query result so  
I can understand better how to find the right threshold for my fuzzy  
queries

4. There is a page dedicated to fuzzy query on ElasticSearch web site,  
but I am not sure it lists all the potential parameters I can use for  
the fuzzy query. Were could I find such an exhaustive list?

5. Same question for the other queries actually.

6. is there a difference between a Fuzzy Query and a Query String  
Query using lucene syntax to get fuzzy matching?

Thanks in advance for your help!

Cheers,  
Adrien

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [April 27, 2012, 9:19am UTC](https://discuss.elastic.co/t/questions-about-fuzzy-query/7467/2 "2012-04-27T09:19:58Z")

</div>

The problem is that the fuzzy query does not analyze the text provided (its  
similar to term query in that regard). For that, we have the option to  
provide "fuzziness" on the text query, which is analyzed. See sample here:  
[gist:2507732 · GitHub](https://gist.github.com/2507732). Note though, fuzzy queries are not fast in  
current Lucene version.

On Thu, Apr 26, 2012 at 4:16 AM, A\_dit\_rien [adrien.ginesty@gmail.com](mailto:adrien.ginesty@gmail.com)wrote:

> Hi guys,
> 
> I am brand new to Elasticsearch, and am currently exploring its  
> features. One of them I am interested in is the fuzzy query, which I  
> am testing and having troubles to use. It is probably a dummy question  
> so I guess someone who already used this feature will quickly find the  
> answer, at least I hope. 🙂
> 
> Actually I already posted this message on StackOverflow but didn't get  
> any answer yet. If you want to take a look, this is the web page:  
> [lucene - ElasticSearch's Fuzzy Query - Stack Overflow](http://stackoverflow.com/questions/10309199/elasticsearchs-fuzzy-query)
> 
> BTW I have the feeling that it might not be only related to  
> Elasticsearch but maybe directly to Lucene.
> 
> Let's start with a new index named "first index" in which I store an  
> object "label" with value "american football". This is the query I  
> use.
> 
> bash-3.2$ curl -XPOST '[http://localhost:9200/firstindex/node/](http://localhost:9200/firstindex/node/)?  
> pretty=true' -d '{ "node" : {  
> "label" : "american football"  
> }  
> }  
> '
> 
> This is the result I get.
> 
> {  
> "ok" : true,  
> "\_index" : "firstindex",  
> "\_type" : "node",  
> "\_id" : "6TXNrLSESYepXPpFWjpl1A",  
> "\_version" : 1  
> }
> 
> So far so good, now I want to find this entry using a fuzzy query.  
> This is the one I send:
> 
> bash-3.2$ curl -XGET '[http://localhost:9200/firstindex/node/\_search](http://localhost:9200/firstindex/node/_search)?  
> pretty=true' -d ' {"query" : {  
> "fuzzy" : {  
> "label" : {  
> "value" : "american football",  
> "boost" : 1.0,  
> "min\_similarity" : 0.0,  
> "prefix\_length" : 0  
> }  
> }  
> }  
> }  
> '
> 
> And this is the result I get
> 
> {  
> "took" : 15,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }
> 
> As you can see, no hit. But now, when I shrink a bit my query's value  
> from "american football" to "american footb" like this:
> 
> bash-3.2$ curl -XGET '[http://localhost:9200/firstindex/node/\_search](http://localhost:9200/firstindex/node/_search)?  
> pretty=true' -d ' {"query" : {  
> "fuzzy" : {  
> "label" : {  
> "value" : "american footb",  
> "boost" : 1.0,  
> "min\_similarity" : 0.0,  
> "prefix\_length" : 0  
> }  
> }  
> }  
> }  
> '
> 
> Then I get a correct hit on my entry, thus the result is:
> 
> { "took" : 0,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 1,  
> "max\_score" : 0.19178301,  
> "hits" : [ {  
> "\_index" : "firstindex",  
> "\_type" : "node",  
> "\_id" : "6TXNrLSESYepXPpFWjpl1A",  
> "\_score" : 0.19178301, "\_source" : {  
> "node" : {  
> "label" : "american football"  
> }  
> }  
> } ]  
> }  
> }
> 
> So, I have several questions related to this test:
> 
> 1. Why I didn't get any result when performing a query with a value  
> completely equals the my only entry "american football"
> 
> 2. Is it related to the fact that I have a multi-words value?
> 
> 3. Is there a way to get the "similarity" score in my query result so  
> I can understand better how to find the right threshold for my fuzzy  
> queries
> 
> 4. There is a page dedicated to fuzzy query on Elasticsearch web site,  
> but I am not sure it lists all the potential parameters I can use for  
> the fuzzy query. Were could I find such an exhaustive list?
> 
> 5. Same question for the other queries actually.
> 
> 6. is there a difference between a Fuzzy Query and a Query String  
> Query using lucene syntax to get fuzzy matching?
> 
> Thanks in advance for your help!
> 
> Cheers,  
> Adrien

---

<div class="post-metadata">

**Author:** ![my3sons](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@my3sons](https://discuss.elastic.co/u/my3sons)\
**Post date:** [May 11, 2012, 4:26pm UTC](https://discuss.elastic.co/t/questions-about-fuzzy-query/7467/3 "2012-05-11T16:26:53Z")

</div>

While trying to solve something similar, I played around with fuzzy  
queries, fuzzy like this queries, fuzziness, and phonetic filters, and what  
actually ended up working best for me was to simply use my query string  
query and append each term with "~", which is a short cut to Lucene's fuzzy  
query. So essentially what I do is submit query using "raw" term(s) entered  
by user, and in the event I get back 0 results, I will resubmit the query,  
using query string query and appending "~" to each of the user entered  
term(s). The results are incredibly relevant. For example, entering "linerd  
skinerd" will return results for one of the greatest rock bands of all time  
"Lynyrd Skynyrd" ! This is really powerful, but beware of performance  
impact, which is why I only use when initial search returns nothing.

On Wednesday, April 25, 2012 8:16:07 PM UTC-5, A\_dit\_rien wrote:

> Hi guys,
> 
> I am brand new to Elasticsearch, and am currently exploring its  
> features. One of them I am interested in is the fuzzy query, which I  
> am testing and having troubles to use. It is probably a dummy question  
> so I guess someone who already used this feature will quickly find the  
> answer, at least I hope. 🙂
> 
> Actually I already posted this message on StackOverflow but didn't get  
> any answer yet. If you want to take a look, this is the web page:  
> [lucene - ElasticSearch's Fuzzy Query - Stack Overflow](http://stackoverflow.com/questions/10309199/elasticsearchs-fuzzy-query)
> 
> BTW I have the feeling that it might not be only related to  
> Elasticsearch but maybe directly to Lucene.
> 
> Let's start with a new index named "first index" in which I store an  
> object "label" with value "american football". This is the query I  
> use.
> 
> bash-3.2$ curl -XPOST '[http://localhost:9200/firstindex/node/](http://localhost:9200/firstindex/node/)?  
> pretty=true [http://localhost:9200/firstindex/node/?pretty=true](http://localhost:9200/firstindex/node/?pretty=true)' -d '{  
> "node" : {  
> "label" : "american football"  
> }  
> }  
> '
> 
> This is the result I get.
> 
> {  
> "ok" : true,  
> "\_index" : "firstindex",  
> "\_type" : "node",  
> "\_id" : "6TXNrLSESYepXPpFWjpl1A",  
> "\_version" : 1  
> }
> 
> So far so good, now I want to find this entry using a fuzzy query.  
> This is the one I send:
> 
> bash-3.2$ curl -XGET '[http://localhost:9200/firstindex/node/\_search](http://localhost:9200/firstindex/node/_search)?  
> pretty=true [http://localhost:9200/firstindex/node/\_search?pretty=true](http://localhost:9200/firstindex/node/_search?pretty=true)'  
> -d ' {"query" : {  
> "fuzzy" : {  
> "label" : {  
> "value" : "american football",  
> "boost" : 1.0,  
> "min\_similarity" : 0.0,  
> "prefix\_length" : 0  
> }  
> }  
> }  
> }  
> '
> 
> And this is the result I get
> 
> {  
> "took" : 15,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }
> 
> As you can see, no hit. But now, when I shrink a bit my query's value  
> from "american football" to "american footb" like this:
> 
> bash-3.2$ curl -XGET '[http://localhost:9200/firstindex/node/\_search](http://localhost:9200/firstindex/node/_search)?  
> pretty=true [http://localhost:9200/firstindex/node/\_search?pretty=true](http://localhost:9200/firstindex/node/_search?pretty=true)'  
> -d ' {"query" : {  
> "fuzzy" : {  
> "label" : {  
> "value" : "american footb",  
> "boost" : 1.0,  
> "min\_similarity" : 0.0,  
> "prefix\_length" : 0  
> }  
> }  
> }  
> }  
> '
> 
> Then I get a correct hit on my entry, thus the result is:
> 
> { "took" : 0,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 1,  
> "max\_score" : 0.19178301,  
> "hits" : [ {  
> "\_index" : "firstindex",  
> "\_type" : "node",  
> "\_id" : "6TXNrLSESYepXPpFWjpl1A",  
> "\_score" : 0.19178301, "\_source" : {  
> "node" : {  
> "label" : "american football"  
> }  
> }  
> } ]  
> }  
> }
> 
> So, I have several questions related to this test:
> 
> 1. Why I didn't get any result when performing a query with a value  
> completely equals the my only entry "american football"
> 
> 2. Is it related to the fact that I have a multi-words value?
> 
> 3. Is there a way to get the "similarity" score in my query result so  
> I can understand better how to find the right threshold for my fuzzy  
> queries
> 
> 4. There is a page dedicated to fuzzy query on Elasticsearch web site,  
> but I am not sure it lists all the potential parameters I can use for  
> the fuzzy query. Were could I find such an exhaustive list?
> 
> 5. Same question for the other queries actually.
> 
> 6. is there a difference between a Fuzzy Query and a Query String  
> Query using lucene syntax to get fuzzy matching?
> 
> Thanks in advance for your help!
> 
> Cheers,  
> Adrien

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 15, 2012, 7:58pm UTC](https://discuss.elastic.co/t/questions-about-fuzzy-query/7467/4 "2012-05-15T19:58:11Z")

</div>

You can use the text query with the fuzziness parameter for that as well.

On Fri, May 11, 2012 at 7:26 PM, my3sons [carey.boldenow@gmail.com](mailto:carey.boldenow@gmail.com) wrote:

> While trying to solve something similar, I played around with fuzzy  
> queries, fuzzy like this queries, fuzziness, and phonetic filters, and what  
> actually ended up working best for me was to simply use my query string  
> query and append each term with "~", which is a short cut to Lucene's fuzzy  
> query. So essentially what I do is submit query using "raw" term(s) entered  
> by user, and in the event I get back 0 results, I will resubmit the query,  
> using query string query and appending "~" to each of the user entered  
> term(s). The results are incredibly relevant. For example, entering "linerd  
> skinerd" will return results for one of the greatest rock bands of all time  
> "Lynyrd Skynyrd" ! This is really powerful, but beware of performance  
> impact, which is why I only use when initial search returns nothing.
> 
> On Wednesday, April 25, 2012 8:16:07 PM UTC-5, A\_dit\_rien wrote:
> 
> > Hi guys,
> > 
> > I am brand new to Elasticsearch, and am currently exploring its  
> > features. One of them I am interested in is the fuzzy query, which I  
> > am testing and having troubles to use. It is probably a dummy question  
> > so I guess someone who already used this feature will quickly find the  
> > answer, at least I hope. 🙂
> > 
> > Actually I already posted this message on StackOverflow but didn't get  
> > any answer yet. If you want to take a look, this is the web page:  
> > [http://stackoverflow.com/\*\*questions/10309199/](http://stackoverflow.com/**questions/10309199/)\*\*  
> > elasticsearchs-fuzzy-query[http://stackoverflow.com/questions/10309199/elasticsearchs-fuzzy-query](http://stackoverflow.com/questions/10309199/elasticsearchs-fuzzy-query)
> > 
> > BTW I have the feeling that it might not be only related to  
> > Elasticsearch but maybe directly to Lucene.
> > 
> > Let's start with a new index named "first index" in which I store an  
> > object "label" with value "american football". This is the query I  
> > use.
> > 
> > bash-3.2$ curl -XPOST '[http://localhost:9200/\*\*firstindex/node/](http://localhost:9200/**firstindex/node/)?  
> > pretty=true [http://localhost:9200/firstindex/node/?pretty=true](http://localhost:9200/firstindex/node/?pretty=true)' -d '{  
> > "node" : {  
> > "label" : "american football"  
> > }  
> > }  
> > '
> > 
> > This is the result I get.
> > 
> > {  
> > "ok" : true,  
> > "\_index" : "firstindex",  
> > "\_type" : "node",  
> > "\_id" : "6TXNrLSESYepXPpFWjpl1A",  
> > "\_version" : 1  
> > }
> > 
> > So far so good, now I want to find this entry using a fuzzy query.  
> > This is the one I send:
> > 
> > bash-3.2$ curl -XGET '[http://localhost:9200/\*\*firstindex/node/\_search](http://localhost:9200/**firstindex/node/_search)?  
> > pretty=true [http://localhost:9200/firstindex/node/\_search?pretty=true](http://localhost:9200/firstindex/node/_search?pretty=true)'  
> > -d ' {"query" : {  
> > "fuzzy" : {  
> > "label" : {  
> > "value" : "american football",  
> > "boost" : 1.0,  
> > "min\_similarity" : 0.0,  
> > "prefix\_length" : 0  
> > }  
> > }  
> > }  
> > }  
> > '
> > 
> > And this is the result I get
> > 
> > {  
> > "took" : 15,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 0,  
> > "max\_score" : null,  
> > "hits" :   
> > }  
> > }
> > 
> > As you can see, no hit. But now, when I shrink a bit my query's value  
> > from "american football" to "american footb" like this:
> > 
> > bash-3.2$ curl -XGET '[http://localhost:9200/\*\*firstindex/node/\_search](http://localhost:9200/**firstindex/node/_search)?  
> > pretty=true [http://localhost:9200/firstindex/node/\_search?pretty=true](http://localhost:9200/firstindex/node/_search?pretty=true)'  
> > -d ' {"query" : {  
> > "fuzzy" : {  
> > "label" : {  
> > "value" : "american footb",  
> > "boost" : 1.0,  
> > "min\_similarity" : 0.0,  
> > "prefix\_length" : 0  
> > }  
> > }  
> > }  
> > }  
> > '
> > 
> > Then I get a correct hit on my entry, thus the result is:
> > 
> > { "took" : 0,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 1,  
> > "max\_score" : 0.19178301,  
> > "hits" : [ {  
> > "\_index" : "firstindex",  
> > "\_type" : "node",  
> > "\_id" : "6TXNrLSESYepXPpFWjpl1A",  
> > "\_score" : 0.19178301, "\_source" : {  
> > "node" : {  
> > "label" : "american football"  
> > }  
> > }  
> > } ]  
> > }  
> > }
> > 
> > So, I have several questions related to this test:
> > 
> > 1. Why I didn't get any result when performing a query with a value  
> > completely equals the my only entry "american football"
> > 
> > 2. Is it related to the fact that I have a multi-words value?
> > 
> > 3. Is there a way to get the "similarity" score in my query result so  
> > I can understand better how to find the right threshold for my fuzzy  
> > queries
> > 
> > 4. There is a page dedicated to fuzzy query on Elasticsearch web site,  
> > but I am not sure it lists all the potential parameters I can use for  
> > the fuzzy query. Were could I find such an exhaustive list?
> > 
> > 5. Same question for the other queries actually.
> > 
> > 6. is there a difference between a Fuzzy Query and a Query String  
> > Query using lucene syntax to get fuzzy matching?
> > 
> > Thanks in advance for your help!
> > 
> > Cheers,  
> > Adrien

---

<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, 3:28am UTC](https://discuss.elastic.co/t/questions-about-fuzzy-query/7467/5 "2017-07-06T03:28:48Z")

</div>


