Search code examples
elasticsearchelasticsearch-7

How to search by part of a synonym


I have products index with mapping

"synonym" : {
    "type" : "synonym",
    "synonyms" : [
        "netbook => laptop"
    ]
}

I want to search my products by query "lapt*" or "netb*"


Solution

  • If searching by lapt* works but not netb* then you need to change your synonyms filter to this (i.e. replace => by a comma):

    "synonym" : {
        "type" : "synonym",
        "synonyms" : [
            "netbook, laptop"
        ]
    }
    

    Using => replaces netbook by laptop and hence only the latter is indexed. Using a comma, will index both netbook and laptop and allow you to search for prefixes with both netb* and lapt*