I have created a collection which contains documents from other collections to enable a sort of global search. It works fine but now I’d like to be able to filter out a set of types that should be included in the search results.
I have a compound query that I’m expanding with a filter operator which works fine when I just what to filter one specific type like this
$search: {
index: "global",
compound: {
should: [
{
autocomplete: {
path: "name",
query: searchTerm,
score: {
boost: {
value: 3,
},
},
},
},
{
text: {
path: "name",
query: searchTerm,
fuzzy: {
maxEdits: 1,
},
},
},
],
minimumShouldMatch: 1,
filter: [
{
equals: {
value: 0,
path: "type",
},
},
],
},
},
What I really want is to have the the filter
accept an array of accepted values but equals
don’t work like that. I need something like $in
but I’m not sure if that exists in search.
I could do the filtering afterwords in the pipeline but that seems inefficient. Any ideas?