# Invalid synonym rule when using two files

**URL:** <https://discuss.elastic.co/t/invalid-synonym-rule-when-using-two-files/158603>\
**Category:** Elasticsearch\
**Created:** [November 28, 2018, 3:14pm UTC](https://discuss.elastic.co/t/invalid-synonym-rule-when-using-two-files/158603 "2018-11-28T15:14:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bilal](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@Bilal](https://discuss.elastic.co/u/Bilal)\
**Post date:** [November 28, 2018, 3:14pm UTC](https://discuss.elastic.co/t/invalid-synonym-rule-when-using-two-files/158603/1 "2018-11-28T15:14:51Z")

</div>

I have two synonyms files with few thousand lines, here is the sample causing the problem:

`en_synonyms` file :

```
cereal, semolina, wheat

```

`fr_synonyms` file :

```
ble, cereale, wheat

```

This is the error I got :

```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 1",
      "caused_by": {
        "type": "illegal_argument_exception",
        "reason": "term: wheat analyzed to a token (cereal) with position increment != 1 (got: 0)"
      }
    }
  },
  "status": 400
}

```

The mapping I used:

```auto
PUT wheat_syn
{
  "mappings": {
    "wheat": {
      "properties": {
        "description": {
          "type": "text",
          "fields": {
            "synonyms": {
              "type": "text",
              "analyzer": "syn_text"
            },
            "keyword": {
             "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    }
  },
  "settings": {
    "number_of_shards": 1,
    "analysis": {
      "filter": {
        "en_synonyms": {
          "type": "synonym",
          "tokenizer": "keyword",
          "synonyms_path" : "analysis/en_synonyms.txt"
        },
        "fr_synonyms": {
          "type": "synonym",
          "tokenizer": "keyword",
          "synonyms_path" : "analysis/fr_synonyms.txt"
        }
      },
      "analyzer": {
        "syn_text": {
          "tokenizer": "standard",
          "filter": ["lowercase", "en_synonyms", "fr_synonyms"]
        }
      }
    }
  }
}

```

Both files containing the term `wheat` when I remove it from one of them, the index is created successfully.

I thought about combining the two files, so the result will be :

```
cereal, semolina, wheat, ble, cereale

```

But in my case I can't do that manually since it will take a lot of time (I'll look for a way to do it programmatically, depending on the answer to this question)

---

<div class="post-metadata">

**Author:** ![Bilal](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@Bilal](https://discuss.elastic.co/u/Bilal)\
**Post date:** [December 5, 2018, 3:26pm UTC](https://discuss.elastic.co/t/invalid-synonym-rule-when-using-two-files/158603/2 "2018-12-05T15:26:02Z")

</div>

Found a simple soltion:

Instead of using two files, I just concatenated the content of `en_synonyms` and `fr_synonyms` in one file `all_synonyms`:

```
cereal, semolina, wheat
ble, cereale, wheat

```

Then used it for the mapping.

---

<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:** [December 6, 2018, 9:40am UTC](https://discuss.elastic.co/t/invalid-synonym-rule-when-using-two-files/158603/3 "2018-12-06T09:40:53Z")

</div>

Hi @Bilal

great you found a solution. Your original problem still seems strange to me, and I'd like to verify the behaviour but didn't find the time to do so right now. Maybe we can improve the way multiple chained synonym filters are handled to avoid such problems.

---

<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:** [December 10, 2018, 2:38pm UTC](https://discuss.elastic.co/t/invalid-synonym-rule-when-using-two-files/158603/4 "2018-12-10T14:38:14Z")

</div>

Hi @Bilal, fyi I opened [https://github.com/elastic/elasticsearch/issues/36433](https://github.com/elastic/elasticsearch/issues/36433) to not forget about this issue. Maybe somebody has a better explanation than me why this behaviour is like it is, but I'd like to keep track of it and investigate if we can improve on the situation here.

---

<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:** [December 10, 2018, 7:48pm UTC](https://discuss.elastic.co/t/invalid-synonym-rule-when-using-two-files/158603/5 "2018-12-10T19:48:44Z")

</div>

Looks like there is something in the works for version 6.6 that will remedy this: [https://github.com/elastic/elasticsearch/pull/34331](https://github.com/elastic/elasticsearch/pull/34331)

---

<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:** [January 7, 2019, 7:48pm UTC](https://discuss.elastic.co/t/invalid-synonym-rule-when-using-two-files/158603/6 "2019-01-07T19:48:45Z")

</div>

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