# Fuzzy search question

**URL:** <https://discuss.elastic.co/t/fuzzy-search-question/228675>\
**Category:** Elasticsearch\
**Created:** [April 18, 2020, 7:34pm UTC](https://discuss.elastic.co/t/fuzzy-search-question/228675 "2020-04-18T19:34:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![giorgio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/giorgio/32/61978_2.png) [@giorgio](https://discuss.elastic.co/u/giorgio)\
**Post date:** [April 18, 2020, 7:34pm UTC](https://discuss.elastic.co/t/fuzzy-search-question/228675/1 "2020-04-18T19:34:19Z")

</div>

Hello I am doing reverse image search using elasticsearch. I have hashes stored in index and now I am trying to find similar hashes(to compensate compression and what not) using Query String fuzziness.  
my code for search is:

```auto
var searchResponse = await Program._elasticclient.SearchAsync<IndexedImage>
                (
                s => s.Index("images").Query(q => q.QueryString(qs => qs.FuzzyMaxExpansions(150).Fuzziness(Fuzziness.EditDistance(150)).Fields(f => f.Field(ff => ff.imagehash)).Query(imagehash))).Size(10000)
                ).ConfigureAwait(false);

```

imagehash field is string holding hash(~600 character long number)  
When I am trying to find similar strings it works fine but it's not working well at some cases and I am wondering whats wrong.  
For example, this is original hash and when searching it returns 2 results from DB:

```auto
222230302101000014343434014133341141303411413033013140410000000304142022222214134313414240103030010130300101101003031110130314133303434110102222222243431000030024241411432324214232141143133431411144421000030034042222222214111333121143232223323211113333333331211311333344442000444340002222222201013434222032323130110111103303323011011110330334330101343111112222222231333111010244440400444434304131141343134444400044441030131133432222222233311131101423130001444401044444434400404444003041410020000034242222222201003414434300000000343430310131303201013131010102003434121143032222224203034444444410002123421201033444343421413434314101044444444230402222

```

This is hash of similar image(levenshtein distance is 52) and when searched db returns 0 results:

```auto
222230302101000024343434014133341141303411413033013140410000000204242022222214134313414140103030010130300101101003031110130314133303424120102222222243431000030034241411432324214222141143133431411144421000030034042222222214111333121243232223323212113333333331211312333344432010444340002222222201013434323021312120120211103303323011011110230333331101343111112222222231333111010244440400444434304131141443134444400044441030131133432222222233311131101423130001444401044444434400404444003041410030000034242222222201003414434300000000343430310131303201013131010101003434222142022222224203024444444410002123421211133343343421413434314101044444444230402222

```

When I took original hash and replaced bunch of numbers with same amount of 9s I got levenshtein distance 59 and search returned 2 results as original. hash:

```auto
222230302101000014343434014133341141303411413033013140410000000304142022222214134313414240103030010130300101101003031110130314133303434110102222222243431000030024241411432324214232141143133431411144421000030034042222222214111333121143232223323211113333333331211311333344442000444340002222222201013434222032323130110199999999999999999999999999999999999999999999999999999999190244440400444434304131141343134444400044441030131133432222222233311131101423130001444401044444434400404444003041410020000034242222222201003414434300000000343430310131303201013131010102003434121143032222224203034444444410002123421201033444343421413434314101044444444230402221

```

all hashes I have stored and ones I am searching are always same in length.  
Similarity can be compared properly here: [https://countwordsfree.com/comparetexts](https://countwordsfree.com/comparetexts)  
Can anyone point me to right direction and tell me what am I doing wrong here? Thanks in advance

---

<div class="post-metadata">

**Author:** ![giorgio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/giorgio/32/61978_2.png) [@giorgio](https://discuss.elastic.co/u/giorgio)\
**Post date:** [April 19, 2020, 12:15pm UTC](https://discuss.elastic.co/t/fuzzy-search-question/228675/2 "2020-04-19T12:15:02Z")

</div>

Anyone?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [April 19, 2020, 1:27pm UTC](https://discuss.elastic.co/t/fuzzy-search-question/228675/3 "2020-04-19T13:27:31Z")

</div>

Which version of Elasticsearch are you using? What is the mapping of the field?

---

<div class="post-metadata">

**Author:** ![giorgio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/giorgio/32/61978_2.png) [@giorgio](https://discuss.elastic.co/u/giorgio)\
**Post date:** [April 19, 2020, 1:35pm UTC](https://discuss.elastic.co/t/fuzzy-search-question/228675/4 "2020-04-19T13:35:16Z")

</div>

Elasticsearch version 7.5.2  
my index mapping:

```auto
{
   "images":{
      "mappings":{
         "properties":{
            "imagehash":{
               "type":"text",
               "fields":{
                  "keyword":{
                     "type":"keyword",
                     "ignore_above":256
                  }
               }
            },
            "data":{
               "type":"text",
               "fields":{
                  "keyword":{
                     "type":"keyword",
                     "ignore_above":256
                  }
               }
            },
            "source":{
               "type":"text",
               "fields":{
                  "keyword":{
                     "type":"keyword",
                     "ignore_above":256
                  }
               }
            }
         }
      }
   }
}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 19, 2020, 1:37pm UTC](https://discuss.elastic.co/t/fuzzy-search-question/228675/5 "2020-04-19T13:37:19Z")

</div>

Please be patient in waiting for responses to your question and refrain from pinging multiple times asking for a response or opening multiple topics for the same question. This is a community forum, it may take time for someone to reply to your question. For more information please refer to the [Community Code of Conduct](https://www.elastic.co/community/codeofconduct) specifically the section "Be patient". Also, please refrain from pinging folks directly, this is a forum and anyone that participates might be able to assist you.

If you are in need of a service with an SLA that covers response times for questions then you may want to consider talking to us about a [subscription](https://www.elastic.co/subscriptions).

It's fine to answer on your own thread after 2 or 3 days (not including weekends) if you don't have an answer.

---

<div class="post-metadata">

**Author:** ![giorgio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/giorgio/32/61978_2.png) [@giorgio](https://discuss.elastic.co/u/giorgio)\
**Post date:** [April 19, 2020, 1:41pm UTC](https://discuss.elastic.co/t/fuzzy-search-question/228675/6 "2020-04-19T13:41:08Z")

</div>

understood sorry.

---

<div class="post-metadata">

**Author:** ![giorgio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/giorgio/32/61978_2.png) [@giorgio](https://discuss.elastic.co/u/giorgio)\
**Post date:** [April 24, 2020, 7:02pm UTC](https://discuss.elastic.co/t/fuzzy-search-question/228675/7 "2020-04-24T19:02:03Z")

</div>

Up. Still have not solved this.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 25, 2020, 8:31am UTC](https://discuss.elastic.co/t/fuzzy-search-question/228675/8 "2020-04-25T08:31:47Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<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:** [May 23, 2020, 8:32am UTC](https://discuss.elastic.co/t/fuzzy-search-question/228675/9 "2020-05-23T08:32:03Z")

</div>

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