Search code examples
azure-cognitive-search

Multi word synonyms in azure search not working


Currently when the user searches "united kingdom", they are also getting results about 'united arab emirates'. I am looking to define a synonym map that would help me show results only about 'United kingdom'

Have tried defining the following synonym map

  1. 'united kingdom, uk\n'
  2. 'united kingdom, uk => tag001\n' - Tried the elastic search way
  3. 'united kingdom => uk\n'

In all the cases I am still getting matches with 'united arab emirates'

Appreciate any help on how to structure the synonym map properly?


Solution

  • Unfortunately, multi-word synonyms are not supported, and this is a known but undocumented limitation. A known workaround is to create a custom analyzer with a SynonymTokenFilter. This will produce the required synonym tokens in the index. Unfortunately, you must rebuild the index to update synonyms.

    Synonyms you update on runtime without rebuilding the index only support single-term synonyms.

    For a detailed description of the workaround, see my recent question Is there a way to make multi term synonyms work in Azure Cognitive Search