# Synonyms and Fuzziness conflict

**URL:** <https://discuss.elastic.co/t/synonyms-and-fuzziness-conflict/90376>\
**Category:** Elasticsearch\
**Created:** [June 22, 2017, 1:53am UTC](https://discuss.elastic.co/t/synonyms-and-fuzziness-conflict/90376 "2017-06-22T01:53:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![guilherme\_maranhao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilherme_maranhao/32/101483_2.png) [@guilherme\_maranhao](https://discuss.elastic.co/u/guilherme_maranhao)\
**Post date:** [June 22, 2017, 1:53am UTC](https://discuss.elastic.co/t/synonyms-and-fuzziness-conflict/90376/1 "2017-06-22T01:53:14Z")

</div>

Hi,

I have an analyzer which contains a synonym filter:

```
analysis: {
             analyzer: {
                 synonym_brazilian_analyzer: {
                     tokenizer: "standard",
                     filter: [
                         "lowercase",
                         "asciifolding",
                         "my_synonyms",
                         "brazilian_stop"
                     ]
                 }
             },
             filter: {
                 brazilian_stop: {
                     type: "stop",
                     stopwords: "_brazilian_"
                 },
                 my_synonyms: {
                     type: "synonym",
                     synonyms_path: "path/synonyms.txt"
                 }
             }
         }

```

My path/synonyms.txt contains:

```
shirt, blouse

```

My query is

```
             query: {
                        multi_match: {
                            fields: %w(name^3
                                  tags_names^2),
                            query: term,
                            fuzziness: "AUTO"
                        }
                    }

```

I have documents which contain the word 'shirt' in the tags\_names field and others documents, the word 'shirts' in the same field.

If I search for 'shirts', because of the 'fuzziness' setting, both documents containing 'shirt' and 'shirts' are retrieved. However, if I search for 'shirt', only the documents with 'shirt' are returned.

Removing the

```
shirt, blouse

```

from my synonym setting file, both queries return the same documents.

Why does it happen when I search for a word which is described in my synonym setting file? Doesn't elasticsearch allow fuzzy searches on words declared in a synonym file?  
How do I deal with that? Can't I use them (fuzziness and synonym) simultaneously when I am searching for a term defined in the synonym file?

Thanks,

Guilherme

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [July 16, 2017, 3:37pm UTC](https://discuss.elastic.co/t/synonyms-and-fuzziness-conflict/90376/2 "2017-07-16T15:37:35Z")

</div>

Hello Guilherme,

The problem is not really related to fuzzyness. You can verify this by doing a test with [Fuzzy Query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html) and you will see that you can not reproduce this.

The issue here is related to Multi Match Query. It seems that when it finds a mapped synonym it completely disregards the fuzzyness. You can verify this using the [Validate API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-validate.html) with the `rewrite` option. For instance:

```auto
GET <index_name>/_validate/query?rewrite=true
{
  "query": {
    "multi_match" : {
      "query": "shirts", 
      "fields": ["names^3", "tags_names^2"],
      "fuzziness": "AUTO"
    }
  }
}

```

Do this with `shirts` and `shirt`. You will see that while the former will be rewritten using fuzzyness, the latter will actually use synonym without any fuzzyness.

TBH, I don't know why this happens (could be a bug?). Maybe @Adrien_Grand has more to tell?

Cheers

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [July 17, 2017, 12:13pm UTC](https://discuss.elastic.co/t/synonyms-and-fuzziness-conflict/90376/3 "2017-07-17T12:13:41Z")

</div>

Might be related to [https://github.com/elastic/elasticsearch/issues/25518](https://github.com/elastic/elasticsearch/issues/25518)?

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [July 17, 2017, 12:17pm UTC](https://discuss.elastic.co/t/synonyms-and-fuzziness-conflict/90376/4 "2017-07-17T12:17:37Z")

</div>

@jpountz I don't think it's the case here since I could _not_ reproduce the behavior using a simple fuzzy query. Fuzzyness was only broken by synonym when doing a multi match

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [July 17, 2017, 1:24pm UTC](https://discuss.elastic.co/t/synonyms-and-fuzziness-conflict/90376/5 "2017-07-17T13:24:37Z")

</div>

Right, because the fuzzy query discards analysis, it is not aware of the configured synonyms.

---

<div class="post-metadata">

**Author:** ![guilherme\_maranhao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilherme_maranhao/32/101483_2.png) [@guilherme\_maranhao](https://discuss.elastic.co/u/guilherme_maranhao)\
**Post date:** [July 17, 2017, 2:02pm UTC](https://discuss.elastic.co/t/synonyms-and-fuzziness-conflict/90376/6 "2017-07-17T14:02:09Z")

</div>

Thank you, everybody.

As it seems to be an opened issue ([https://github.com/elastic/elasticsearch/issues/25518](https://github.com/elastic/elasticsearch/issues/25518)), for now, I'll remove the fuzzy query from my search and use only the synonym filter, as it's more important for me.

Thank you again,

Guilherme

---

<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 14, 2017, 2:02pm UTC](https://discuss.elastic.co/t/synonyms-and-fuzziness-conflict/90376/7 "2017-08-14T14:02:14Z")

</div>

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