I’m searching through a collection either by hard data (numbers, other values) with $match and operaters like $regex, $in, $eq, $size, $gte, etc.
{'$match': {'$and': [{'isbn': {'$exists': 1}}, {'form': {'$in': ['BC']}}]}}
With $facet I can count the found matches.
For other purposes I use a $search index for nifty text search. I get scores and highlight and the lots, and again (but not with $facet) the count of found matches.
$search': {
'index': 'default',
'compound': {
'must': [
how...
],
},
'count': {'type': 'total'},
}
I can combine $match and $search, but cannot get a proper count. $search is not combinable with $facet, and without the $facet the text search always counts what the text search finds, not taking into account the unmatched documents.
How can I combina the both? Adding compound filters or using the limitied amount of operators within Atlas’s text search are not sufficient.
Bottom line, this is all about proper counting of results.
Thanks.
2
Answers
Solution!
What is not menioned in the documentation (at least not findable), is the possibility to use regex in a filter.
This way i can replace the whole match part.
And it works fast and perfect.
Thanks for the help.
Short answer is you can’t.
The
$search
stage uses a completely different index and methodology to "match" documents, therefor there are the limitations that it has to be the first step in a pipeline and can’t be nested in a$facet
.Removing these limitations will essentially just run 2 queries, which is what you must do.
An approach that is possible in ElasticSearch is to use the children pipeline, but as far as i’m aware this is not a feature available on atlas search yet.