# Fuzzy

**URL:** <https://discuss.elastic.co/t/fuzzy/5423>\
**Category:** Elasticsearch\
**Created:** [September 21, 2011, 5:29am UTC](https://discuss.elastic.co/t/fuzzy/5423 "2011-09-21T05:29:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kalpana\_pinnaka](https://avatars.discourse-cdn.com/v4/letter/k/ed8c4c/32.png) [@kalpana\_pinnaka](https://discuss.elastic.co/u/kalpana_pinnaka)\
**Post date:** [September 21, 2011, 5:29am UTC](https://discuss.elastic.co/t/fuzzy/5423/1 "2011-09-21T05:29:00Z")

</div>

Hi, I want a command to get the "nearest word" of a miss-spell word  
using fuzzy query.

for example: i have put a command like this

curl -XPUT [http://localhost:9200/lowang/ets/11](http://localhost:9200/lowang/ets/11) -d '  
{  
"\_id":11,  
"title":"smartfon nokia 5678"  
}

and i use a search command like below

curl -XGET [http://localhost:9200/lowang/ets/\_search](http://localhost:9200/lowang/ets/_search) -d '{  
"query": {  
"bool": {  
"must":[  
{ "fuzzy": { "title": { "value" : "noia" } } }  
]  
}  
}}'

and now i got the results like below

{"took":35,"timed\_out":false,"\_shards":{"total":5,"successful":  
5,"failed":0},"hits":{"total":1,"max\_score":0.15342641,"hits":  
[{"\_index":"lowang","\_type":"ets","\_id":"11","\_score":0.15342641,  
"\_source" :  
{  
"\_id":11,  
"title":"smartfon nokia 5678"  
}}]}}

internally...using fuzzy query logic ..it is calculating nearest word  
for "noia" as "nokia"..and it giving results for the word "nokia".

Instead of results i want to display the "nearest word" of a miss-  
spelled word.

How to i can get?

---

<div class="post-metadata">

**Author:** ![AEvar\_Arnfjord\_Bjarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aevar_arnfjord_bjarm/32/2746_2.png) [@AEvar\_Arnfjord\_Bjarm](https://discuss.elastic.co/u/AEvar_Arnfjord_Bjarm)\
**Post date:** [September 21, 2011, 5:40pm UTC](https://discuss.elastic.co/t/fuzzy/5423/2 "2011-09-21T17:40:00Z")

</div>

On Wed, Sep 21, 2011 at 07:29, kalpana pinnaka [saikalpana18@gmail.com](mailto:saikalpana18@gmail.com) wrote:

> internally...using fuzzy query logic ..it is calculating nearest word  
> for "noia" as "nokia"..and it giving results for the word "nokia".
> 
> Instead of results i want to display the "nearest word" of a miss-  
> spelled word.

I dealt with this problem today and just wrote code that for a given  
resultset for a fuzzy result:

- Got the first result in the set
- Tokenized the words in it
- Tokenized the words I'd given Elasticsearch
- Compared the Levenshtein distance between all words and took into  
account their length
- Got words like "nokia" back for "noia"

I wish there was an easier API for this, but I haven't found it yet.

---

<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:53am UTC](https://discuss.elastic.co/t/fuzzy/5423/3 "2017-07-06T03:53:54Z")

</div>

Closed on July 6, 2017, 3:53am UTC


