在 Elasticsearch 中连续使用同义词过滤器

问题描述

我想按如下顺序使用两个同义词过滤器

PUT test
{
  "settings": {
    "index" : {
      "analysis": {
        "filter": {
          "english_stop": {
              "type": "stop","stopwords": "_english_"
            },"synonyms1": {
            "type": "synonym_graph","synonyms": [
              "cake,pudding"
            ]
          },"synonyms2": {
            "type": "synonym_graph","synonyms": [
              "chocolate cake => chocolate_cake","caramel cake => caramel_pudding"
            ]
          }
        },"analyzer": {
          "default_search": {
            "type": "custom","tokenizer": "standard","filter": [
              "asciifolding","lowercase","english_stop","porter_stem","synonyms1","synonyms2"
            ] 
          }
        }
      }
    }
  }
}

我收到以下错误

{
  "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: chocolate cake analyzed to a token (cake) with position increment != 1 (got: 0)"
      }
    }
  },"status" : 400
}

我的目标是连续应用我的两个同义词过滤器,以便能够运行以下请求

GET test/_analyze
{
  "text": "chocolate pudding","analyzer": "default_search"
}

并将“巧克力布丁”转换为“巧克力蛋糕布丁”(使用 synonyms1),最后使用 synonyms2 转换为“巧克力蛋糕布丁”。

如何使我的过滤器工作?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)