# Multi words synonym query issues

**URL:** <https://discuss.elastic.co/t/multi-words-synonym-query-issues/208679>\
**Category:** Elasticsearch\
**Created:** [November 20, 2019, 11:02am UTC](https://discuss.elastic.co/t/multi-words-synonym-query-issues/208679 "2019-11-20T11:02:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasoncodingguru](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@jasoncodingguru](https://discuss.elastic.co/u/jasoncodingguru)\
**Post date:** [November 20, 2019, 11:02am UTC](https://discuss.elastic.co/t/multi-words-synonym-query-issues/208679/1 "2019-11-20T11:02:42Z")

</div>

Hi guys,

I am having a challenge with multi words synonym related queries. E.g I have the following format of synonym:

Spanish onion, red onion

I have a document which contains words “onion red”. When I use multi match “cross\_fields” searching with query “red onion”, or “Spanish onion”, it doesn’t return the above product. It looks like adding the synonym filter caused the problem. I tried to specify “slop”, however it didn’t work at all. Does anyone have any ideas?

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [November 21, 2019, 6:49pm UTC](https://discuss.elastic.co/t/multi-words-synonym-query-issues/208679/2 "2019-11-21T18:49:35Z")

</div>

You don't provide a lot of details with regards to how you have implemented these synonyms, but I'm assuming you're using the `synonym_graph` token filter in a search analyzer?

When you define multi-word synonyms using the `synonym_graph` token filter, those multi-words are then treated as phrases, even in a regular match query (or multi\_match query). So, by defining `spanish onion` and `red onion` as synonyms, you will now no longer search for `red OR onion`, but for the phrase `"red onion"` (and its synonyms) instead. This is why you can't find your document.

As a way around this you could use a bool query that searches both with and without synonyms, by overriding the `analyzer` to be the `standard` analyzer in one of the queries. That would look something like this:

```auto
GET my_index/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "red onion",
            "fields": [
              "my_field"
            ],
            "type": "cross_fields"
          }
        },
        {
          "multi_match": {
            "query": "red onion",
            "fields": [
              "my_field"
            ],
            "type": "cross_fields",
            "analyzer": "standard"
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![jasoncodingguru](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@jasoncodingguru](https://discuss.elastic.co/u/jasoncodingguru)\
**Post date:** [November 21, 2019, 9:31pm UTC](https://discuss.elastic.co/t/multi-words-synonym-query-issues/208679/3 "2019-11-21T21:31:10Z")

</div>

Hi Abodn,

Thanks for your reply and suggestions.

It was resolved by setting the parameter “ auto\_generate\_synonyms\_phrase\_query“ to false.

---

<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:** [December 19, 2019, 9:31pm UTC](https://discuss.elastic.co/t/multi-words-synonym-query-issues/208679/4 "2019-12-19T21:31:15Z")

</div>

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