Say I just have one document in a collection
{
_id: <whatever>,
sound: 'Dong'
}
and a synonyms collection with only one mapping
{
mappingType: 'explicit',
input: ['Ding'],
synonyms: ['Ding', 'Dong']
}
and I want to create a search index which uses those to return the one document when one queries for 'Ding'
on the property sound
.
In this minimal example I can just use the lucene.standard
analyzer and all works perfectly (lucene.english
works as well). But changing just the analyzer definitions to lucene.keyword
(and custom analyszers, but there I might be making another mistake) breaks things, i.e. no document is returned. The definitions are pretty straight-forward; search index field definition
"sound": {
"analyzer": "lucene.keyword",
"searchAnalyzer": "lucene.keyword",
"type": "string"
},
and synonyms
"synonyms": [
{
"analyzer": "lucene.keyword",
"name": "synonym_mapping",
"source": {
"collection": "synonyms"
}
}
]
Using MongoDB Compass to explain the query, I can see that for lucene.standard
and lucene.english
the explain looks slightly different (type: "DefaultQuery"
and "queryType": "SafeTermAutomatonQueryWrapper"
sounds like a wrapper for synonyms is used, maybe?) than for the not-working analyzers (type: "TermQuery"
), but there is no documentation on what everything means.
At this point, my best guess is that either some analyzers are not supposed to work with synonyms (I couldn’t find anything in the docs though, no error or warning either obviously), or the implementation to handle that case is missing.
Am I doing something wrong?