Search code examples
elasticsearchelasticsearch-mongo-river

trying to add mapping in elasticseach


I am trying to add analyzer and mapping in my elastic search index but I get this error;

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

My index name products and type product.my setting -

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

I am using latest version of elastic search.


Solution

  • Assuming synonyms.txt exists, I think this will fix your problem:

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

    You don't need the "products" entry in "settings".