0

I have products index with mapping

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

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

  • You can check the `prefix` query – Val Jul 17 '20 at 04:10
  • @Val, thanks but question is not how to search by prefix and how to search by part of synonym – Vadim Selyakov Jul 17 '20 at 06:30
  • 1
    In your example, you examplified prefix search, not infix search, that's why I suggested the prefix query – Val Jul 17 '20 at 06:31
  • @VadimSelyakov it has been a long time that you have not upvoted my answer, it would be great if u can accept and upvote the answer if your issue is resolved – Amit Aug 04 '20 at 08:51

1 Answers1

2

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*

Val
  • 188,334
  • 12
  • 317
  • 323