My objective is to create a search pipeline in MongoDB, that returns result for multiple fields.
My index:
{
"analyzer": "lucene.standard",
"searchAnalyzer": "lucene.standard",
"mappings": {
"dynamic": false,
"fields": {
"description": {
"analyzer": "lucene.standard",
"type": "string"
},
"name": {
"type": "string"
}
}
}
}
My $search
pipeline stage:
{
$search: {
index: 'lucene.standard',
queryString: {
defaultPath: 'name',
query: `name:"${query}" OR description:"${query}"`,
},
}
}
This works, but only when I search for a full word.
For example, if a have a document with description fooBar
.
My problem is that if I query for foo
- I get no results.
Only works when I query for the full word fooBar
.
How can I fix this - maybe be using another index definition?