0

I have a synonym filter:

'honeycombs, honey in honeycombs => honey'

Some goods contain this words in title.

If user search for honey, I need to sort it as

  1. Сontains honey
  2. Contains honeycombs
  3. Contains honey in honeycombs
  4. Others

Is there a proper way to do what?

SiZE
  • 2,217
  • 1
  • 13
  • 24

1 Answers1

1

As far as I know it is not possible in Elasticsearch to assign weight to Synonyms which is available in Lucene as well as Solr.

There is one workaround you can use at query time and it will boost the document for actual query and lower boost of synonyms keyword.

Let consider, you have field name title and define with the search or index time synonyms filter. You can add actual query to should clause for same with standard analayzer.

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "title": "honey"
          }
        }
      ],
      "should": [
        {
          "match": {
            "title": {
              "query": "honey",
              "analyzer": "standard"
            }
          }
        }
      ]
    }
  }
}
Sagar Patel
  • 4,993
  • 1
  • 8
  • 19
  • Thanks for you answer. The weight of synonym looks like what am I need. Sorry cant accept your answer as it has no decision for me. – SiZE Jun 01 '22 at 09:24