I use mongo DB Atlas with autocomplete.
It works fine if in the json configuration I insert fields that are not nested:
{
"mappings": {
"dynamic": false,
"fields": {
"model": [
{
"foldDiacritics": false,
"maxGrams": 10,
"minGrams": 4,
"type": "autocomplete"
}
],
"title": [
{
"foldDiacritics": false,
"maxGrams": 10,
"minGrams": 3,
"type": "autocomplete"
}
]
}
}
}
But in my DB I have a nested object “optional.hash” and according to the doc I should do something like that:
{
"mappings": {
"dynamic": false,
"fields": {
"optional.hash": [
{
"foldDiacritics": false,
"maxGrams": 10,
"minGrams": 3,
"type": "autocomplete"
}
],
"model": [
{
"foldDiacritics": false,
"maxGrams": 10,
"minGrams": 4,
"type": "autocomplete"
}
],
"title": [
{
"foldDiacritics": false,
"maxGrams": 10,
"minGrams": 3,
"type": "autocomplete"
}
]
}
}
}
Then the aggregation pipeline is:
[
{
$search: {
compound: {
should: [
{
autocomplete: {
query: `${query}`,
path: 'model',
fuzzy: {
maxEdits: 2,
prefixLength: 3,
maxExpansions: 256,
},
},
},
{
autocomplete: {
query: `${query}`,
path: 'title',
tokenOrder: 'sequential',
fuzzy: {
maxEdits: 1,
prefixLength: 1,
maxExpansions: 256,
},
},
},
{
autocomplete: {
query: `${query}`,
path: 'optional.hash',
tokenOrder: 'sequential',
},
},
],
minimumShouldMatch: 1,
},
},
},
And it has always worked but not anymore. I had to make sure that the value for the autocomplete is not nested in an object and so it works.
Anyone else have the same problem as me?