Search code examples
elasticsearchelastic-stackfuzzy-searchdamerau-levenshtein

Fuzziness not behaving as expected in Elasticsearch


I am trying to test few test cases for my project which I am doing in Elasticsearch. The result given by the fuzziness query is confusing for a particular case :- While searching for Mall keyword with fuzziness 2 applied in multi-match query its also matching Mile.

As per fuzziness documentation :-
=> 0 edits are allowed for string length is 0-2 .
=> 1 edit is allowed for  string length is 3-5.
=> 2 edits are allowed for string length greater than 5.

If this is the case why did MILE matched with MALL, because as per logic only one edit should be allowed and if we see for MALL->MILE we need 2 edits. Is Elasticsearch behaving as expected or am I missing something here. I am using simple whitespace analyzer for the field and query using

         {  "query": {
            "multi_match": {
                "query": "mall",
                "fields": [
                          "name"
                 ],
                 "fuzziness": 2
          } }}

Solution

  • The documentation you have highlighted is only for when you specify "fuzziness": "AUTO", otherwise if you specify a normal number (0, 1 or 2), then that number is taken into account (in your case, 2)