Invalid synonym rule when using two files

丶灬走出姿态 提交于 2020-01-16 15:41:52

问题


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 :

{
  "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:

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 contain 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)


回答1:


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.



来源:https://stackoverflow.com/questions/53536461/invalid-synonym-rule-when-using-two-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!