# I could not fuzzy search in Elasticsearch

**URL:** <https://discuss.elastic.co/t/i-could-not-fuzzy-search-in-elasticsearch/146127>\
**Category:** Elasticsearch\
**Created:** [August 27, 2018, 8:34am UTC](https://discuss.elastic.co/t/i-could-not-fuzzy-search-in-elasticsearch/146127 "2018-08-27T08:34:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ercancavusoglu](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ercancavusoglu](https://discuss.elastic.co/u/ercancavusoglu)\
**Post date:** [August 27, 2018, 8:34am UTC](https://discuss.elastic.co/t/i-could-not-fuzzy-search-in-elasticsearch/146127/1 "2018-08-27T08:34:51Z")

</div>

I want to autocomplete service via Elasticsearch.I need a "did you mean" of google style. I researched very much how can I to do. I was find a fuzzy search. When I entered to "Alman", I want to Almanya only. But I received Umman too. How can I getting only "almanya"?

```
    {
        "highlight": {"fields": [{"CountryName": {"type": "plain"}}]},
        "query": {
            "bool": {
                "should": [
                    {
                        "match": {
                            "CountryName": {
                                "boost": 1,
                                "fuzziness": 5,
                                "query": "Alman"
                            }
                        }
                    },
                    {
                        "match": {
                            "CountryNameTurkish": {
                                "boost": 1,
                                "fuzziness": 5,
                                "query": "Alman"
                            }
                        }
                    }
                ]
            }
        }
    }

```

Response

```
    {
        "hits": {
            "total": 2,
            "max_score": 1.9666269,
            "hits": [
                {
                    "_index": "country_codes_v1",
                    "_type": "kafka_connect",
                    "_id": "OM",
                    "_score": 1.9666269,
                    "_source": {
                        "CountryCode": "OM",
                        "CountryName": "Oman",
                        "Continent": "Middle East",
                        "CapitalCityCode": "MCT",
                        "Duplicate": 0,
                        "CountrySlug": "om-oman",
                        "CountryNameTurkish": "Umman"
                    }
                },
                {
                    "_index": "country_codes_v1",
                    "_type": "kafka_connect",
                    "_id": "DE",
                    "_score": 1.6418773,
                    "_source": {
                        "CountryCode": "DE",
                        "CountryName": "Germany",
                        "Continent": "Europe",
                        "CapitalCityCode": "BER",
                        "Duplicate": 0,
                        "CountrySlug": "de-germany",
                        "CountryNameTurkish": "Almanya"
                    }
                }
            ]
        }
    }
```

---

<div class="post-metadata">

**Author:** ![Ana\_Maria\_Rusu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ana_maria_rusu/32/34782_2.png) [@Ana\_Maria\_Rusu](https://discuss.elastic.co/u/Ana_Maria_Rusu)\
**Post date:** [August 28, 2018, 8:25am UTC](https://discuss.elastic.co/t/i-could-not-fuzzy-search-in-elasticsearch/146127/2 "2018-08-28T08:25:19Z")

</div>

Hi,

You set there fuzziness to 5. Fuzziness uses Levenshtein edit distance which measures the number of single-character edits required to transform one word in another. It has four types of one-character edits:

- Substitution of one character to another: \_f\_ox -\> \_b\_ox
- Insertion of a new character: sic -\> sic\_k\_
- Deletion of a character: b\_l\_ack -\> back
- Transposition of two adjacent characters: \_st\_ar -\> \_ts\_ar

When you set fuzziness to 5 you set the edit distance to 5, and between Alman and Umman the edit distance is 2, so fuzzy search match this word. You can set the edit distance to [AUTO](https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#fuzziness) and also you can set a [prefix\_length](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html) if you think it could filter your fuzzy results.

---

<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:** [September 25, 2018, 8:25am UTC](https://discuss.elastic.co/t/i-could-not-fuzzy-search-in-elasticsearch/146127/3 "2018-09-25T08:25:20Z")

</div>

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