Hi, I am trying the atlas search. Facing some unexpected behavior. Like I want to search zip code, I write this piece. Then I run the script to execute the query 3000 times so that I can check its performance.
{
$search: {
index: “zipcode_search”,
“autocomplete”: {
“path”: “searchKey”,
“query”:payload.search
}
}
}
In comparison to the above query. I write this query also. So that I can compare how much-indexed search is better than traditional searches.
` {` ` $match: {` ` $or: [` ` { zipcode: { $regex: '^' + data, $options: "si" } },` ` { city: { $regex: '^' + data, $options: "si" } }` ` ]` ` }` ` }`
But the results are totally opposite to what I thought.
The traditional query works way better than the indexed one. Both of them are giving results.
I don’t know, why this is happening?
Is my index working in the indexed search query or not, How can I confirm? Or am I doing something work here?
The number of documents examined by the $search query is 0 and the other query examined 299 documents there is a total of 42000 documents in the zipcode collection and there is an index on zip code and city.
The avg execution time of $search query is higher than $match query.
When $search query is running then load on zipcode collection goes up to 100%. But on $match load goes up to 10%.