# Fuzzy search

**URL:** <https://discuss.elastic.co/t/fuzzy-search/283603>\
**Category:** Elasticsearch\
**Created:** [September 8, 2021, 4:37am UTC](https://discuss.elastic.co/t/fuzzy-search/283603 "2021-09-08T04:37:48Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Danzo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danzo/32/87914_2.png) [@Danzo](https://discuss.elastic.co/u/Danzo)\
**Post date:** [September 8, 2021, 4:37am UTC](https://discuss.elastic.co/t/fuzzy-search/283603/1 "2021-09-08T04:37:48Z")

</div>

Hello, I am trying to do a fuzzy search for my data. But my query returns null

Create index

```auto
PUT /test_index
{
  "mappings": {
      "properties": {
        "testt": {
          "type": "text"
        }    
      }
    }
}

```

Mapping my index

```auto
GET /test_index/_mapping?pretty
{
  "test_index" : {
    "mappings" : {
      "properties" : {
        "testt" : {
          "type" : "text"
        }
      }
    }
  }
}

```

Query. I expect that the request will return a document, where the **testt** with the value **Moscow**

```auto
GET /test_index/_search?pretty
{
  "query": {
     "match": {
      "testt": {
        "query": "Mascow",
        "fuzziness": "auto",
		"operator": "and"
      }             
   	}
  }
}

```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 8, 2021, 4:43am UTC](https://discuss.elastic.co/t/fuzzy-search/283603/2 "2021-09-08T04:43:32Z")

</div>

Welcome to our community! 😃

Can you share a sample doc?

---

<div class="post-metadata">

**Author:** ![Danzo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danzo/32/87914_2.png) [@Danzo](https://discuss.elastic.co/u/Danzo)\
**Post date:** [September 8, 2021, 4:54am UTC](https://discuss.elastic.co/t/fuzzy-search/283603/4 "2021-09-08T04:54:08Z")

</div>

This my search GET /test\_index/\_search?pretty  
[pastebin result](https://pastebin.com/bhDxETic)

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 8, 2021, 4:56am UTC](https://discuss.elastic.co/t/fuzzy-search/283603/5 "2021-09-08T04:56:25Z")

</div>

Ok but an example of the document in Elasticsearch would be useful.

---

<div class="post-metadata">

**Author:** ![Danzo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danzo/32/87914_2.png) [@Danzo](https://discuss.elastic.co/u/Danzo)\
**Post date:** [September 8, 2021, 5:12am UTC](https://discuss.elastic.co/t/fuzzy-search/283603/7 "2021-09-08T05:12:16Z")

</div>

my [example](https://pastebin.com/9Hw5ct4k) of the document

---

<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:** [September 8, 2021, 9:43am UTC](https://discuss.elastic.co/t/fuzzy-search/283603/8 "2021-09-08T09:43:57Z")

</div>

Working for me:

```auto
DELETE test
PUT /test
{
  "mappings": {
      "properties": {
        "testt": {
          "type": "text"
        }    
      }
    }
}

POST test/_doc/1
{
  "testt":"Moscow"
}
POST test/_search
{
  "query": {
    "match": {
      "testt": {
        "query": "Mascow",
        "fuzziness": "auto",
        "operator": "and"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Danzo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danzo/32/87914_2.png) [@Danzo](https://discuss.elastic.co/u/Danzo)\
**Post date:** [September 8, 2021, 10:19am UTC](https://discuss.elastic.co/t/fuzzy-search/283603/9 "2021-09-08T10:19:00Z")

</div>

It really works, but do you know how to implement support for the Russian language?)

i just do it

```auto
PUT /test
{
  "mappings": {
      "properties": {
        "testt": {
          "type": "text",
           "analyzer": "russian"
        }    
      }
    }
}

```

and also tried like this:

```auto
{
  "settings": {
    "analysis": {
      "analyzer": "russian"
    }
  },
  "mappings": {
	  "properties": {
	    "testt": { "type": "string" }
	  }
  }
}

```

---

<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:** [September 8, 2021, 10:25am UTC](https://discuss.elastic.co/t/fuzzy-search/283603/10 "2021-09-08T10:25:17Z")

</div>

What was wrong with the first example in your last comment?

---

<div class="post-metadata">

**Author:** ![Danzo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danzo/32/87914_2.png) [@Danzo](https://discuss.elastic.co/u/Danzo)\
**Post date:** [September 8, 2021, 10:38am UTC](https://discuss.elastic.co/t/fuzzy-search/283603/11 "2021-09-08T10:38:51Z")

</div>

I'm trying to make sure that when the city is incompletely written, I get an approximately suitable list.  
Example: i request with value "San" and take response "San Diego", "San Jose", "San Francisco", "Santa Rosa", "Santa Maria"  
Now: i request with value "Masc" and take response nothing, but if request "Mascow" my response "Moscow"

---

<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:** [September 8, 2021, 10:56am UTC](https://discuss.elastic.co/t/fuzzy-search/283603/12 "2021-09-08T10:56:32Z")

</div>

Fuzzy search will only help you match where there's max 2 characters different between search term and indexed term.

To match "San" with "San Diego" in the city field it sounds like you want to use a prefix query and to use a `keyword` field with a lower case normalizer.

---

<div class="post-metadata">

**Author:** ![Danzo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danzo/32/87914_2.png) [@Danzo](https://discuss.elastic.co/u/Danzo)\
**Post date:** [September 8, 2021, 11:03am UTC](https://discuss.elastic.co/t/fuzzy-search/283603/13 "2021-09-08T11:03:03Z")

</div>

Just week ago i created index and my full address have city, street, number house (example: Moscow, str. Avtozavodskay, h. 26). My request with "avtozav" and he returned full address (look example)

---

<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:** [September 8, 2021, 11:07am UTC](https://discuss.elastic.co/t/fuzzy-search/283603/14 "2021-09-08T11:07:27Z")

</div>

> (look example)

If we are to diagnose any problems we need JSON examples for a mapping, document and search otherwise we can't reproduce what is being discussed and be certain of what problem might exist.

---

<div class="post-metadata">

**Author:** ![Danzo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danzo/32/87914_2.png) [@Danzo](https://discuss.elastic.co/u/Danzo)\
**Post date:** [September 8, 2021, 11:49am UTC](https://discuss.elastic.co/t/fuzzy-search/283603/15 "2021-09-08T11:49:32Z")

</div>

mapping:

```auto
PUT /addresses
{
  "settings": {
    "analysis": {
      "analyzer": "russian"
    }
  },
  "mappings": {
	  "properties": {
	    "address": { "type": "text" }
	  }
  }
}

```

documents:

```auto
POST addresses/_doc/1
{
  "address": "Moscow, str. Avtozavodskay, h. 26"
}

POST addresses/_doc/2
{
  "address": "Moscow, str. Avtozavodskay, h. 32"
}

POST addresses/_doc/3
{
  "address": "Moscow, str. Lenina, h. 1"
}

```

search:

```auto
POST /address/_search
{
  "query": {
    "match": {
      "address": {
        "query": "str avtozavod",
        "fuzziness": "auto",
        "operator": "and"
      }
    }
  }
}

```

I expect to see

```auto
{
    "took": ...,
    "timed_out": ...,
    "_shards": {...},
    "hits": {
        "total": {
            "value": 2,
            "relation": "eq"
        },
        "max_score": ...,
        "hits": [
            {
                "_index": "address",
                "_type": "_doc",
                "_id": "1",
                "_score": 0.99045343,
                "_source": {
                    "address": "Moscow, str. Avtozavodskay, h. 26"
                }
            },
            {
                "_index": "address",
                "_type": "_doc",
                "_id": "2",
                "_score": 0.9904123,
                "_source": {
                    "address": "Moscow, str. Avtozavodskay, h. 32"
                }
            }
        ]
    }
}

```

---

<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:** [September 8, 2021, 12:35pm UTC](https://discuss.elastic.co/t/fuzzy-search/283603/16 "2021-09-08T12:35:32Z")

</div>

Your settings for the analyzer look messed up.  
Also, as I [stated earlier](https://discuss.elastic.co/t/fuzzy-search/283603/12), a max of 2 character differences are permitted between search term and indexed term so a search for `avtozavod` will not match `avtozavodskay` because that is 4 characters different. In the example below I have a 2 character difference and it works:

```auto
PUT /addresses
{

  "mappings": {
	  "properties": {
	    "address": { "type": "text", "analyzer": "russian" }
	  }
  }
}
POST addresses/_doc/1
{
  "address": "Moscow, str. Avtozavodskay, h. 26"
}

POST addresses/_doc/2
{
  "address": "Moscow, str. Avtozavodskay, h. 32"
}

POST addresses/_doc/3
{
  "address": "Moscow, str. Lenina, h. 1"
}

POST /addresses/_search
{
  "query": {
    "match": {
      "address": {
        "query": "stz avtozavodskzz",
        "fuzziness": "auto",
        "operator": "and"
      }
    }
  }
}

```

---

<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:** [October 6, 2021, 12:35pm UTC](https://discuss.elastic.co/t/fuzzy-search/283603/17 "2021-10-06T12:35:55Z")

</div>

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