Firstly, I have a pipeline that works well:
{
pipeline: [
{
$search: {
index: 'full-text-index',
compound: {
// filter: [
// {
// equals: {
// value: new ObjectId(userId),
// path: 'user_id',
// },
// },
// ],
should: [
{
autocomplete: {
path: 'sentence',
query: term,
tokenOrder: 'any',
fuzzy: {
maxEdits: 2,
prefixLength: 1,
maxExpansions: 256,
},
},
},
{
text: {
query: term,
path: 'note',
},
},
{
text: {
query: term,
path: 'translation',
},
},
],
minimumShouldMatch: 1,
},
sort: { score: { $meta: 'searchScore' } },
},
},
{ $limit: ENTRIES_PER_PAGE },
{
$addFields: {
id: { $toString: '$_id' },
sentencePlusPhoneticSymbols: '$sentence_plus_phonetic_symbols',
},
},
{
$project: {
_id: 0,
id: 1,
sentencePlusPhoneticSymbols: 1,
translation: 1,
note: 1,
score: { $meta: 'searchScore' },
},
},
],
}
except that the commented-out filter clause will break things up, causing no data to be returned from this pipeline.
I use bson
package for the ObjectId constructor, which should be legit.
Below is the index settings:
{
"mappings": {
"dynamic": true,
"fields": {
"note": {
"multi": {
"note_chinese": {
"analyzer": "lucene.chinese",
"searchAnalyzer": "lucene.chinese",
"type": "string"
}
},
"type": "string"
},
"sentence": [
{
"type": "string"
},
{
"type": "autocomplete"
}
],
"translation": {
"analyzer": "lucene.chinese",
"searchAnalyzer": "lucene.chinese",
"type": "string"
}
}
}
}
I attached a document in the target collection below. What I did wrong? Please help.