Help using Search Synonyms

Hello Community,
I have encountered a possible problem using synonyms.
image

  • When I attempt to search for something and the search query contains many words, I get no output at all.

  • When the query consists of a single word, I get the output that you’d expect from a normal behaviour.

  • Removing the synonyms field also gives normal behaviour.

  • Changing all analayzers to lucene.standard doesn’t help at all.

It is written in the documentation that a synonym must consist of a single word, but nothing is said about the query.

Am I doing something wrong ?

Hi @wael_kassem

To get a better idea of what you are trying to achieve, could you provide the following:

  1. The search aggregation you’re currently using in text format so that we may copy and paste if required
  2. The expected output for the provided search aggregation
  3. MongoDB version

Regards,
Jason

1 Like

I am using the following equivalent synonyms :
[“car”,“vehicle”,“automobile”]

And here’s my document:
{"_id":{"$oid":“62b1c77d5b26cca04adad1f1”},“text”:“I took my gasoline red vehicle to the repair shop”}

{
  index: 'default',
  text: {
    query: 'car ',
    path: ['text']

  },
  highlight:{path: ['text']}
}

The following pipeline doesn’t get any matches, which is expected because i didn’t include a synonyms parameter. Once I include the synonyms parameter , I get my expected output.

{
  index: 'default',
  text: {
    query: 'car to the repair',
    path: ['text']
  },
  highlight:{path: ['text']}
}

The following pipeline gets my matches, which isn’t expected because i didn’t include a synonyms parameter. Once I include the synonyms parameter , I don’t get matches anymore.

Please be aware of the multi word query .
Thank you,

We are using MongoAtlas version 5.0.9

Hi @wael_kassem - Thanks for providing those details.

/// Text search index called "synindex"
{
  index: 'synindex',
  text: {
    query: 'car to the repair',
    path: ['text']
  },
  highlight:{path: ['text']}
}

The following pipeline gets my matches, which isn’t expected because i didn’t include a synonyms parameter.

On my test environment using the lucene.standard analyser, I do also get back the document you had mentioned using this search pipeline definition. I believe this behaviour is due to the following noted on the text operator, specific to the query field:

The string or strings to search for. If there are multiple terms in a string, Atlas Search also looks for a match for each term in the string separately.

Once I include the synonyms parameter , I don’t get matches anymore.

This does appear a bit odd due to the synonym working on the singular query example you provided above. Would you be able to provide:

  1. The search index definition
  2. The appropriate document(s) in the source collection where the synonyms for the example (I presume for the word car) are defined. I have provided an example document at the very end of my reply
  3. Confirm if the below behaviour in my example is the behaviour you are expecting with the multi string query and synonyms parameter used.

For the troubleshooting purposes, I have the following search pipeline using the synonyms parameter which does return the document you provided:

/// pipeline:
[{$search: {
  index: 'synindex',
  text: {
    query: 'car to the repair',
    path: ['text'],
    synonyms:"syn"
  },
  highlight:{path: ['text']}
}}]

/// output document:
  {
    _id: ObjectId("62b23ed41585d2a73cdd92ec"),
    text: 'I took my gasoline red vehicle to the repair shop'
  }

Please note that if I change the query value to "car", the same document is returned as well.

The source collection document for the above example:

  {
    _id: ObjectId("62b25bf91585d2a73cdd92ed"),
    mappingType: 'equivalent',
    synonyms: [ 'car', 'vehicle', 'automobile' ]
  }

Regards,
Jason

3 Likes

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