So the problem statement is - I am using atlas search for searching product data and have product details in multiple languages. For which, I have used multi analyzer and defined standard and corresponding language analyzer on the same field, so as to get the matching products in any of the case. The requirement is, since it's a product search I need to return atleast some suggestions for users to have a look at and get to the product via returned search results. Here is the mapping I have used after having researched for how to apply multiple analyzers on a single field :
{
"mappings": {
"dynamic": false,
"fields": {
"name": {
"type": "string",
"analyzer": "lucene.standard",
"multi": {
"german": { //german is the name that I have given to this analyzer
"analyzer": "lucene.german",
"type": "string"
},
"french": { //french is the name that I have given to this analyzer
"analyzer": "lucene.french",
"type": "string"
}
}
}
}
}
}
Now, what I want is - if I am searching for a word in english or german or french, I must get a result. Which also is fine with this mapping, I am getting results for all the three languages. But the usecase is, I want result in any of these cases:
- Search string is in English, German or French
- Search string is fuzzy (has spelling mistakes)
- Search string has any special characters or whitespaces
- Search string can be considered as a whole term and results can be returned on the basis of that.
All the above requirements makes me to use all analyzers - standard, keyword, language, whitespace and simple. But this is increasing index size to more than 3KB (which is an upper limit) plus I am not getting result even for the mapping I have currently where I have applied only language and standard analyzer.
The Mongodb Atlas search documentation
Path Construction
helped me to get how I can do that without complexing the query and without use of
compound
operator. From the documentation:This is what I modified in my query :