# How do I implement the synonym dictionary - step-by-step?

**URL:** <https://discuss.elastic.co/t/how-do-i-implement-the-synonym-dictionary-step-by-step/287094>\
**Category:** Elasticsearch\
**Created:** [October 19, 2021, 1:21pm UTC](https://discuss.elastic.co/t/how-do-i-implement-the-synonym-dictionary-step-by-step/287094 "2021-10-19T13:21:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick\_N](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@Nick\_N](https://discuss.elastic.co/u/Nick_N)\
**Post date:** [October 19, 2021, 1:21pm UTC](https://discuss.elastic.co/t/how-do-i-implement-the-synonym-dictionary-step-by-step/287094/1 "2021-10-19T13:21:17Z")

</div>

I want to look for all the jackets that are blue (in the "name" and "tags" fields).  
But the color blue has many shades.  
How do I implement the dictionary of synonyms?  
(I tried many things, without conclusive results with a multitude of depreciation and errors.)  
I currently use version 7.8 and the ability to update to 7.15.

References

> **[Boosting the power of Elasticsearch with synonyms](https://www.elastic.co/blog/boosting-the-power-of-elasticsearch-with-synonyms)**
>
> How to use synonyms and synonym filters in Elasticsearch. Synonyms are a powerful tool for increasing the recall of your search system, but there are many subtleties that are important to know and experiment with, especially in conjunction with...

> **[Synonyms Dictionaries in Elasticsearch | Qbox HES](https://qbox.io/blog/synonyms-dictionaries-in-elasticsearch/)**
>
> Learn about synonym dictionaries in Elasticsearch. While stemming helps to broaden the scope of search by simplifying inflected words to their root form, synonyms broaden the scope by relating concepts and ideas.

```auto
#"analysis/synonym.txt"
# these colors are synonymous 
cyan, cobalt, blue, pacific blue

```

```auto
PUT /test_index
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  },
  "mappings": {
    "properties": {
      "name": {
        "type": "text"
      },
      "tags": {
        "type": "text"
      },
      "description": {
        "type": "text"
      },
      "status": {
        "type": "short"
      }
    }
  }
}

```

```auto
POST _bulk
{ "index" : { "_index" : "test_index", "_id" : "1" } }
{"name": "Product blue jacket XXL", "tags": ["blue", "jacket", "tag1"], "status": 1, "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit."}
{ "index" : { "_index" : "test_index", "_id" : "2" } }
{"name": "Product cyan jacket", "tags": ["cyan", "jacket", "tag2"], "status": 1, "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit."}
{ "index" : { "_index" : "test_index", "_id" : "3" } }
{"name": "Product cobalt jacket", "tags": ["cobalt", "jacket", "tag2"], "status": 1, "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit."}
{ "index" : { "_index" : "test_index", "_id" : "4" } }
{"name": "Product crystal blue", "tags": ["blue", "crystal", "tag4"], "status": 1, "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit."}
{ "index" : { "_index" : "test_index", "_id" : "5" } }
{"name": "Product five", "tags": ["blue", "red", "tag5"], "status": 1, "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit."}
{ "index" : { "_index" : "test_index", "_id" : "6" } }
{"name": "Product blue large jacket", "tags": ["blue", "jacket", "tag6"], "status": 2, "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit."}

```

```auto
GET test_index/_search/
{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "status": 1
          }
        }
      ],
      "must": {
        "multi_match": {
          "query": "blue jacket",
          "type": "best_fields",
          "fields": [
            "tags^10",
            "name^1"
          ],
          "tie_breaker": 0.3,
          "operator": "and"
        }
      }
    }
  },
  "sort": {
    "_score": "desc"
  }
}

```

I want to thank you in advance

---

<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:** [October 20, 2021, 2:43am UTC](https://discuss.elastic.co/t/how-do-i-implement-the-synonym-dictionary-step-by-step/287094/2 "2021-10-20T02:43:58Z")

</div>

Welcome to our community! 😃

You don't seem to have anywhere in your index definition that imports your synonyms though. [Synonym token filter | Elasticsearch Guide [7.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.15/analysis-synonym-tokenfilter.html) has an example at the top of the page, and you have none of what it requires.

> [@Nick\_N](#):
>
> I currently use version 7.8 and the ability to update to 7.15.

Please do upgrade, 7.8 is very nearly [EOL](https://www.elastic.co/support/eol).

---

<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:** [November 17, 2021, 2:44am UTC](https://discuss.elastic.co/t/how-do-i-implement-the-synonym-dictionary-step-by-step/287094/3 "2021-11-17T02:44:03Z")

</div>

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