试图在elasticseach中添加映射

时间:2015-05-09 21:57:36

标签: elasticsearch elasticsearch-mongo-river

我正在尝试在弹性搜索索引中添加analyzermapping但我收到此错误;

[Error: MapperParsingException[mapping [product]]; nested: MapperParsingException[Analyzer [synonym] not found for field [name]];

我的索引名称产品和类型product.my设置 -

{
  "settings": {
    "products": {
      "analysis":{
        "analyzer":{
          "synonym":{
            "tokenizer": "my_ngram",
            "filter":[
              "synonym"
            ]
          }
        },
        "tokenizer" : {
            "my_ngram" : {
                "type" : "nGram",
                "min_gram" : "2",
                "max_gram" : "3",
                "token_chars": [ "letter", "digit" ]
            }
        },
        "filter":{
          "synonym": {
            "type": "synonym",
            "synonyms_path": "synonyms.txt",
            "ignore_case": "true"
          }
        }
      }
    }
  },
  "mappings":{
    "product":{
      "_all":{
        "enabled": true,
      },
      "properties":{
        "name":{
          "type": "string",
           "index": "analyzed",
           "analyzer": "synonym"             
        }
      }
    }
  }
}

我正在使用最新版本的弹性搜索。

1 个答案:

答案 0 :(得分:2)

假设synonyms.txt存在,我认为这将解决您的问题:

{
   "settings": {
      "analysis": {
         "analyzer": {
            "synonym": {
               "tokenizer": "my_ngram",
               "filter": [
                  "synonym"
               ]
            }
         },
         "tokenizer": {
            "my_ngram": {
               "type": "nGram",
               "min_gram": "2",
               "max_gram": "3",
               "token_chars": [
                  "letter",
                  "digit"
               ]
            }
         },
         "filter": {
            "synonym": {
               "type": "synonym",
               "synonyms_path": "synonyms.txt",
               "ignore_case": "true"
            }
         }
      }
   },
   "mappings": {
      "product": {
         "_all": {
            "enabled": true
         },
         "properties": {
            "name": {
               "type": "string",
               "index": "analyzed",
               "analyzer": "synonym"
            }
         }
      }
   }
}

您不需要"products"中的"settings"条目。