# ES6.2.3 synonym filter error

**URL:** https://discuss.elastic.co/t/es6-2-3-synonym-filter-error/132804
**Category:** 日本語による質問・議論はこちら
**Created:** [May 22, 2018, 11:50am UTC](https://discuss.elastic.co/t/es6-2-3-synonym-filter-error/132804 "2018-05-22T11:50:23Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mkokui](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mkokui/32/28320_2.png) [@mkokui](https://discuss.elastic.co/u/mkokui)
#### Post date: [May 22, 2018, 11:50am UTC](https://discuss.elastic.co/t/es6-2-3-synonym-filter-error/132804/1 "2018-05-22T11:50:24Z")

</div>

synonymの定義を外部ファイルから読み込ませてIndexを作成しようとしているのですが、エラーが生じます。  
原因特定の為、以下のようなシンプルな定義を作成してIndexの作成を実行したのですが、エラーが再現しました。何が原因でエラーが発生するのか、回避方法をどうすればよいのかがわかりません。  
何かご存知でしたら教えて頂けないでしょうか。

■定義ファイル

```auto
{
  "settings": {
    "index": {
      "number_of_shards": "3",
      "number_of_replicas": "1",
      "analysis": {
        "tokenizer": {
          "kuromoji": {
            "type": "kuromoji_tokenizer"
          }
        },
        "filter": {
          "synonym": {
            "type": "synonym",
            "synonyms": [
              "ダイレクトバンキング=>ネットバンキング"
            ]
          }
        },
        "analyzer": {
          "kuromoji_analyzer": {
            "type": "custom",
            "tokenizer": "kuromoji",
            "filter": [
              "synonym"
            ]
          }
        }
      }
    }
  }
}

```

■確認しているエラーメッセージ

```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: ダイレクトバンキング analyzed to a token (ダイレクトバンキング) with position increment != 1 (got: 0)"
      }
    }
  },
  "status": 400
}

```

「 "バンキング=\>ネットバンキング"」 ・・では、正常にIndexが作成されました。

---

<div class="post-metadata">

### Author: ![mkokui](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mkokui/32/28320_2.png) [@mkokui](https://discuss.elastic.co/u/mkokui)
#### Post date: [May 22, 2018, 12:46pm UTC](https://discuss.elastic.co/t/es6-2-3-synonym-filter-error/132804/2 "2018-05-22T12:46:22Z")

</div>

「error\_trace=true」パラメータを使用してログを確認してみたのと、

```auto
"stack_trace": "[[xxxxx.localdomain][xxxxx:9300][indices:admin/create]]; nested: RemoteTransportException[[xxxxx.localdomain][xxxxx:9300][indices:admin/create]]; nested: IllegalArgumentException[failed to build synonyms]; nested: NotSerializableExceptionWrapper[parse_exception: Invalid synonym rule at line 1]; nested: IllegalArgumentException[term: ダイレクトバンキング analyzed to a token (ダイレクトバンキング) with position increment != 1 (got: 0)]; at org.elasticsearch.ElasticsearchException.guessRootCauses(ElasticsearchException.java:619) at org.elasticsearch.ElasticsearchException.generateFailureXContent(ElasticsearchException.java:564) at ...

```

kuromojiで、「ダイレクトバンキング」を「analyze」しました結果です。

```auto
{
  "tokens": [
    {
      "token": "ダイレクト",
      "start_offset": 0,
      "end_offset": 5,
      "type": "word",
      "position": 0
    },
    {
      "token": "ダイレクトバンキング",
      "start_offset": 0,
      "end_offset": 10,
      "type": "word",
      "position": 0,
      "positionLength": 2
    },
    {
      "token": "バンキング",
      "start_offset": 5,
      "end_offset": 10,
      "type": "word",
      "position": 1
    }
  ]
}

```

tokenizerは、デフォルトのSEARCHなのですが、Analyze結果に同じものが取得されているのが原因？でしょうか。これは正常な挙動？？  
「NORMAL」「EXTENDED」モードではエラーなく、Indexが作成されました。

で、どうするかなんですが、モードを変えるとAnalyze結果が大きく変わってしまうと思うので、辞書ファイルにSynonymと同じ単語を登録して回避できないかを後日試してみようかと思います。

他に良い方法があればナレッジ頂けると嬉しいです。

---

<div class="post-metadata">

### Author: ![Justin\_Treher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/justin_treher/32/45243_2.png) [@Justin\_Treher](https://discuss.elastic.co/u/Justin_Treher)
#### Post date: [May 29, 2018, 6:22pm UTC](https://discuss.elastic.co/t/es6-2-3-synonym-filter-error/132804/3 "2018-05-29T18:22:20Z")

</div>

> <https://github.com/elastic/elasticsearch/issues/27481>

---

<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: [June 26, 2018, 6:22pm UTC](https://discuss.elastic.co/t/es6-2-3-synonym-filter-error/132804/4 "2018-06-26T18:22:21Z")

</div>

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