在弹性搜索中为单个索引实现多个synonym_path

时间:2016-04-07 08:13:46

标签: elasticsearch synonym

我正在尝试为elasticsearch中的单个索引实现多个synonym_path

"settings": {
"index": {
  "analysis": {
    "analyzer": {
      "synonym": {
        "tokenizer": "whitespace",
        "filter": ["synonym"]
      }
    },
    "filter": {
      "bool": {
          "should": [{
            "synonym": {
              "type": "synonym",
              "synonyms_path": "synonyms.txt",
              "ignore_case": true
            }},
          {
            "synonym": {
              "type": "synonym",
              "synonyms_path": "synonyms2.txt",
              "ignore_case": true
          }}]
      }
    }
  }
}
},
  "mappings": {
    "animals": {
      "properties": {
        "name": {
          "type": "String",
          "analyzer": "synonym"
        }
      }
    }
  }

我在Chrome中使用JSON Sense尝试了上面的代码段,但它生成了TokenFilter [bool] must have a type associated with it错误。

还有其他方法可以实现吗?

1 个答案:

答案 0 :(得分:2)

filter部分中的analysis部分并不包含查询DSL,而是token filter定义。

在您的情况下,您需要使用以下设置重新创建索引:

{
  "settings": {
    "index": {
      "analysis": {
        "analyzer": {
          "synonyms": {
            "tokenizer": "whitespace",
            "filter": [
              "synonym1",
              "synonym2"
            ]
          }
        },
        "filter": {
            "synonym1": {
              "type": "synonym",
              "synonyms_path": "synonyms.txt",
              "ignore_case": true
            },
            "synonym2": {
              "type": "synonym",
              "synonyms_path": "synonyms2.txt",
              "ignore_case": true
            }
        }
      }
    }
  },
  "mappings": {
    "animals": {
      "properties": {
        "name": {
          "type": "string",
          "analyzer": "synonyms"
        }
      }
    }
  }
}