# Get text similarity by Levenstein distance in range 0-1

**URL:** <https://discuss.elastic.co/t/get-text-similarity-by-levenstein-distance-in-range-0-1/241399>\
**Category:** Elasticsearch\
**Created:** [July 16, 2020, 7:13am UTC](https://discuss.elastic.co/t/get-text-similarity-by-levenstein-distance-in-range-0-1/241399 "2020-07-16T07:13:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_D](https://avatars.discourse-cdn.com/v4/letter/a/f0a364/32.png) [@Alex\_D](https://discuss.elastic.co/u/Alex_D)\
**Post date:** [July 16, 2020, 7:13am UTC](https://discuss.elastic.co/t/get-text-similarity-by-levenstein-distance-in-range-0-1/241399/1 "2020-07-16T07:13:24Z")

</div>

Hi all !

I search by a text field and want to get a similarity score for the entire phrase.  
Algorithm - Levenshtein distance.  
The result should be normalized in the range 0 - 1

**Example:**  
text in query:

```auto
"big hat"

```

expected relevance score in the response:

```auto
* "big hat": 1.0
* "not big hat": 0.7
* "big black hat": 0.6

```

I've already figured out some of the limitations of ES:

- max fuzziness value for match query = 2
- if we don't have the same text in ES documents as in the query, we can't understand reference result (with score 1.0)
- TF/IDF similarity works with tokens, not with the entire phrase and takes into account the general occurrence of the token in the index

Maybe there are some things to try.

Will be glad to any comments,  
thanks

---

<div class="post-metadata">

**Author:** ![Alex\_D](https://avatars.discourse-cdn.com/v4/letter/a/f0a364/32.png) [@Alex\_D](https://discuss.elastic.co/u/Alex_D)\
**Post date:** [July 16, 2020, 11:50am UTC](https://discuss.elastic.co/t/get-text-similarity-by-levenstein-distance-in-range-0-1/241399/2 "2020-07-16T11:50:12Z")

</div>

Maybe another similarity module ?  
I use BM25 (by default)

---

<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:** [August 13, 2020, 12:02pm UTC](https://discuss.elastic.co/t/get-text-similarity-by-levenstein-distance-in-range-0-1/241399/3 "2020-08-13T12:02:01Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
