Synonym analyzer issue in elastic search

I have multiple products in elastic index with width as like 10", 10 inch, 10 inches. While searching for 10" laptop, search query was providing me all results with 10" but including 10 as well (as i am using tokenizer as whitespace). However, requirement is to get all 10", 10 inch and 10 inches. I am not looking for something with only 10 as description.

Here are the settings:

"settings": {
"index": {
  "analysis": {
    "filter": {
      "synonym": {
        "type": "synonym",
        "synonyms" : [
            "\", inch, inches"
          ]
      },
      "stopfilter": {
        "type": "stop",
        "stopwords": [
          "and",
          "the"
        ]
      },
      "stemmer": {
        "type": "stemmer",
        "name": "minimal_english"
      }
    },
    "analyzer": {
      "synonym_stemmer": {
        "filter": [
          "lowercase",
          "asciifolding",             
          "synonym",
          "stopfilter"
        ],
        "tokenizer": "whitespace"
      },
      "synonym_stemmer_std": {
        "filter": [
          "lowercase",
          "asciifolding",
          "synonym",
          "stopfilter",              
          "stemmer"
        ],
        "tokenizer": "standard"
      }
      }
    }
}

However while reindexing, I am getting error:


> {
  "index": "products-2019.08.08.0.00",
  "type": "doc",
  "id": "DDA16D00HO",
  "cause": {
    "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: \" was completely eliminated by analyzer"
      }
    }
  },
  "status": 400
},

I tried creating synonym like 10" to 10 inch, it works, but fails as i have tokenizer as whitespace, so it again searches for 10 also. And i don't want such a synonym, i want generic one for " to inch/inches.

Why am i getting this exception if " is first letter with escape character, how to achieve the required result.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.