# Unable to read 'synonym' file while creating index

**URL:** <https://discuss.elastic.co/t/unable-to-read-synonym-file-while-creating-index/183596>\
**Category:** Elasticsearch\
**Created:** [May 30, 2019, 6:55pm UTC](https://discuss.elastic.co/t/unable-to-read-synonym-file-while-creating-index/183596 "2019-05-30T18:55:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gauresh\_chavan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gauresh_chavan/32/42510_2.png) [@gauresh\_chavan](https://discuss.elastic.co/u/gauresh_chavan)\
**Post date:** [May 30, 2019, 6:55pm UTC](https://discuss.elastic.co/t/unable-to-read-synonym-file-while-creating-index/183596/1 "2019-05-30T18:55:05Z")

</div>

I am trying to build a synonym dictionary and write it to an index. Index is being created in the following way:

```auto
PUT /test_index
{
    "settings": {
        "index" : {
            "analysis" : {
                "filter" : {
                    "synonym_filter" : {
                        "type" : "synonym",
                        "synonyms_path" : "C:\\elasticsearch-7.1.0\\config\\synonym.txt",
                        "ignore_case": true
                    }
                },
                "analyzer" : {
                    "synonym_analyzer" : {
                        "tokenizer" : "standard",
                        "filter" : ["lowercase", "synonym_filter"] 
                    }
                }
            }
        }
    },
    "mappings": {
            "properties": {
              "note_text": { 
                "type": "text",
                "analyzer": "synonym_analyzer"
                         }
                          }
        
               }
}

```

However this gives me an error saying...

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "IOException while reading synonyms_path_path: C:\\elasticsearch-7.1.0\\config\\synonyms.txt"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "IOException while reading synonyms_path_path: C:\\elasticsearch-7.1.0\\config\\synonyms.txt",
    "caused_by": {
      "type": "no_such_file_exception",
      "reason": "C:\\elasticsearch-7.1.0\\config\\synonyms.txt"
    }
  },
  "status": 400
}

```

Any help is appreciated!

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [June 3, 2019, 9:57am UTC](https://discuss.elastic.co/t/unable-to-read-synonym-file-while-creating-index/183596/2 "2019-06-03T09:57:49Z")

</div>

Try just "synonyms.txt". Note that synonyms.txt must be in the same directory that the configuration file since that path is relative to the config dir.

---

<div class="post-metadata">

**Author:** ![gauresh\_chavan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gauresh_chavan/32/42510_2.png) [@gauresh\_chavan](https://discuss.elastic.co/u/gauresh_chavan)\
**Post date:** [June 3, 2019, 3:19pm UTC](https://discuss.elastic.co/t/unable-to-read-synonym-file-while-creating-index/183596/3 "2019-06-03T15:19:47Z")

</div>

Hey Chris, i tried that but i still get an error

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "failed to build synonyms"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "failed to build synonyms",
    "caused_by": {
      "type": "parse_exception",
      "reason": "Invalid synonym rule at line 3",
      "caused_by": {
        "type": "illegal_argument_exception",
        "reason": "term: was completely eliminated by analyzer"
      }
    }
  },
  "status": 400
}

```

 ![kibana_error](https://us1.discourse-cdn.com/elastic/original/3X/5/0/50fdeea0c916e16cddea2a67f02cf08eaef80633.png)

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [June 3, 2019, 6:50pm UTC](https://discuss.elastic.co/t/unable-to-read-synonym-file-while-creating-index/183596/4 "2019-06-03T18:50:54Z")

</div>

> [@gauresh\_chavan](#):
>
> "term: was completely eliminated by analyzer"

This is a different error than before. It tells you that some rule in your synonyms file (line 3) is bad. Usually the offending term appears after "term: " which is why I think this might be a blank line or something in your file. The error points out that some input terms in your synonyms file can never match because they get eliminated by the analysis chain the precedes the synonym filter.

---

<div class="post-metadata">

**Author:** ![gauresh\_chavan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gauresh_chavan/32/42510_2.png) [@gauresh\_chavan](https://discuss.elastic.co/u/gauresh_chavan)\
**Post date:** [June 3, 2019, 7:34pm UTC](https://discuss.elastic.co/t/unable-to-read-synonym-file-while-creating-index/183596/5 "2019-06-03T19:34:38Z")

</div>

I figured what the problem was. I was writing synonyms in quotations (replicating how i would write it in the painless query)

So instead of writing,

```auto
ipod => IPOD,
i-pod => IPOD

```

I was writing,

```auto
"ipod => IPOD",
"i-pod => IPOD"

```

---

<div class="post-metadata">

**Author:** ![gauresh\_chavan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gauresh_chavan/32/42510_2.png) [@gauresh\_chavan](https://discuss.elastic.co/u/gauresh_chavan)\
**Post date:** [June 5, 2019, 3:56pm UTC](https://discuss.elastic.co/t/unable-to-read-synonym-file-while-creating-index/183596/6 "2019-06-05T15:56:14Z")

</div>

Hi Chris,

Looks like the problem is not yet solved. Because when I put the file name instead of the entire path. The script runs successfully but the synonyms inside are not really mapped.

However when do it explicitly in the code like below, i get the results correctly.

```auto
PUT diabetes_notes
{
  "settings": {
    "index": {
    "analysis": {
      "filter": {
        "synonym_filter" : {
          "type" : "synonym",
          "synonyms" : ["depression => Depression",
"Major depression => Depression",
"Major depressive disorder => Depression",
"mental depression => Depression"]
        },
        "autocomplete_filter" : {
          "type": "edge_ngram",
          "min_gram": 4,
          "max_gram": 10
        }
      },
      "analyzer": {
        "synonym_analyzer" : {
        "tokenizer" : "standard",
        "filter" : ["lowercase","synonym_filter"] 
        },
        "autocomplete_analyzer" : {
          "tokenizer" : "standard",
          "filter" : ["lowercase","autocomplete_filter"] 
        }
      }
    }
  }
}
}

```

---

<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:** [July 3, 2019, 3:56pm UTC](https://discuss.elastic.co/t/unable-to-read-synonym-file-while-creating-index/183596/7 "2019-07-03T15:56:17Z")

</div>

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