# Fuzziness with Keyword and Text fields

**URL:** <https://discuss.elastic.co/t/fuzziness-with-keyword-and-text-fields/240266>\
**Category:** Elasticsearch\
**Created:** [July 8, 2020, 5:43am UTC](https://discuss.elastic.co/t/fuzziness-with-keyword-and-text-fields/240266 "2020-07-08T05:43:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![psramkumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/psramkumar/32/31393_2.png) [@psramkumar](https://discuss.elastic.co/u/psramkumar)\
**Post date:** [July 8, 2020, 5:43am UTC](https://discuss.elastic.co/t/fuzziness-with-keyword-and-text-fields/240266/1 "2020-07-08T05:43:03Z")

</div>

#### 

"When querying `text` or `keyword` fields, `fuzziness` is interpreted as a Levenshtein Edit Distance"

Based on the above statement from [Fuzziness Document](https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#fuzziness), the query should work the same for both fields.  
Please correct me if I'm wrong

here is how the Mapping goes, copying the same data to keyword field and text field

```auto
    "properties":{
            "id":{"type":"keyword"},
            "name":{"type":"keyword", "copy_to": ["name_factor_k", "name_factor_t"]},
            "accNames": {"type":"keyword", "copy_to": ["name_factor_k", "name_factor_t"]},
            "name_factor_k": {"type":"keyword"},
            "name_factor_t": {"type":"text"}
        }

```

Here is how my Query goes.  
Query 1 with Keyword Field

```auto
    "query": {
    "match": {
      "name_factor_k": {
        "query": "youtube",
        "fuzziness": "AUTO",
        "operator": "AND"
      }
    }
  }

```

Query 2 with Text Field

```auto
 "query": {
    "match": {
      "name_factor_t": {
        "query": "youtube",
        "fuzziness": "AUTO",
        "operator": "AND"
      }
    }
  } 

```

I'm expecting same result for both query but only byText field is returning right result.

FYI:-  
accNames: ["YOUTUBE INC.", "GOOGLE WEB", "ALPHABET" and so on]

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [July 8, 2020, 9:07am UTC](https://discuss.elastic.co/t/fuzziness-with-keyword-and-text-fields/240266/2 "2020-07-08T09:07:52Z")

</div>

> [@psramkumar](#):
>
> I'm expecting same result for both query but only byText field is returning right result.

text fields do matching on individual words eg `youtube` or `inc` whereas keyword fields match the whole string value ie `youtube inc.`. You have to do more than 2 character changes (the max fuzziness) before `youtube inc.` is the same as the search string

---

<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 5, 2020, 9:07am UTC](https://discuss.elastic.co/t/fuzziness-with-keyword-and-text-fields/240266/3 "2020-08-05T09:07:59Z")

</div>

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