# Levenshtein distance

**URL:** <https://discuss.elastic.co/t/levenshtein-distance/17780>\
**Category:** Elasticsearch\
**Created:** [May 28, 2014, 12:10pm UTC](https://discuss.elastic.co/t/levenshtein-distance/17780 "2014-05-28T12:10:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrian\_C](https://avatars.discourse-cdn.com/v4/letter/a/2acd7d/32.png) [@Adrian\_C](https://discuss.elastic.co/u/Adrian_C)\
**Post date:** [May 28, 2014, 12:10pm UTC](https://discuss.elastic.co/t/levenshtein-distance/17780/1 "2014-05-28T12:10:22Z")

</div>

Hi,

I am new to ES and have been doing some simple testing of fuzzy matching. I  
have a query related to Levenshtein distance. Does ElasticSearch  
use Levenshtein distance or Damerau–Levenshtein distance?

For example I have the following text stored in an index (analyzer: simple):  
AARONS

When search using 'arosn' the text is not found. The queries that I have  
been testing with are as follows:

{  
"size":50,  
"query":{  
"fuzzy":{  
"surname":{  
"value":"arosn",  
"fuzziness":2,  
"prefix\_length":1,  
"max\_expansions":100  
}  
}  
}  
}

and

{  
"size":50,  
"query":{  
"match":{  
"surname":{  
"query":"arosn",  
"fuzziness":2  
}  
}  
}  
}

{  
"size":50,  
"query":{  
"match":{  
"surname":{  
"query":"arosn~",  
"fuzziness":2  
}  
}  
}  
}

{  
"size":50,  
"query":{  
"query\_string":{  
"default\_field":"surname",  
"fuzziness":2,  
"query":"arosn~2"  
}  
}  
}

If the Damerau–Levenshtein distance algorithm was is use then I would  
expect this to match with a distance of two:

arosn + (a) à aarosn + swap (n & s) à aarons

I am a little confused as there is reference to Damerau–Levenshtein:  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#\_fuzziness](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_fuzziness)

So any ideas on how I can get Damerau–Levenshtein to work?

Thanks

--  
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/c9b9fb8b-d1f4-46d8-9426-a1dc1a729c9a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c9b9fb8b-d1f4-46d8-9426-a1dc1a729c9a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Adrian\_C](https://avatars.discourse-cdn.com/v4/letter/a/2acd7d/32.png) [@Adrian\_C](https://discuss.elastic.co/u/Adrian_C)\
**Post date:** [May 29, 2014, 1:35pm UTC](https://discuss.elastic.co/t/levenshtein-distance/17780/2 "2014-05-29T13:35:36Z")

</div>

Resolved this by setting transpositions true on the request - didn't see  
this option documented but found it by looking through the source.

{  
"size":50,  
"query":{  
"fuzzy":{  
"surname":{  
"value":"arosn",  
"transpositions":true,  
"fuzziness":2,  
"prefix\_length":1,  
"max\_expansions":100  
}  
}  
}  
}

On Wednesday, 28 May 2014 13:10:22 UTC+1, Adrian C wrote:

> Hi,
> 
> I am new to ES and have been doing some simple testing of fuzzy matching.  
> I have a query related to Levenshtein distance. Does Elasticsearch  
> use Levenshtein distance or Damerau–Levenshtein distance?
> 
> For example I have the following text stored in an index (analyzer:  
> simple):  
> AARONS
> 
> When search using 'arosn' the text is not found. The queries that I have  
> been testing with are as follows:
> 
> {  
> "size":50,  
> "query":{  
> "fuzzy":{  
> "surname":{  
> "value":"arosn",  
> "fuzziness":2,  
> "prefix\_length":1,  
> "max\_expansions":100  
> }  
> }  
> }  
> }
> 
> and
> 
> {  
> "size":50,  
> "query":{  
> "match":{  
> "surname":{  
> "query":"arosn",  
> "fuzziness":2  
> }  
> }  
> }  
> }
> 
> {  
> "size":50,  
> "query":{  
> "match":{  
> "surname":{  
> "query":"arosn~",  
> "fuzziness":2  
> }  
> }  
> }  
> }
> 
> {  
> "size":50,  
> "query":{  
> "query\_string":{  
> "default\_field":"surname",  
> "fuzziness":2,  
> "query":"arosn~2"  
> }  
> }  
> }
> 
> If the Damerau–Levenshtein distance algorithm was is use then I would  
> expect this to match with a distance of two:
> 
> arosn + (a) à aarosn + swap (n & s) à aarons
> 
> I am a little confused as there is reference to Damerau–Levenshtein:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_fuzziness)
> 
> So any ideas on how I can get Damerau–Levenshtein to work?
> 
> Thanks

--  
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/e4cf61f0-1c6c-42d4-a01a-e51598bdf196%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e4cf61f0-1c6c-42d4-a01a-e51598bdf196%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:26am UTC](https://discuss.elastic.co/t/levenshtein-distance/17780/3 "2017-07-06T01:26:06Z")

</div>


