Hi
So I have a sample collection Posts
which I filled with 10 million documents for testing purposes. The schema is as follows
`_id
username
title
body
tags
likes
shares
date`
The text index is on (title, body, tags)
- a simple search like the following returns in 0ms
db.posts.find({$text: {$search: “technology computer phone”}}).limit(50)
Of course I realise this is just taking the first 50 documents which match the search stems, then returning them. What I would want is for the more relevant/higher scoring matches to appear first though
db.posts.find({$text: {$search: “technology computer phone”}}).sort({score:{$meta:“textScore”}}).limit(50)
This query takes much longer, however - about 10 seconds. So I have a few questions:
-
Is there anyway to speed this up in pure MongoDB?
-
For a search like this on 10 million documents, where 1.25 million match the search terms (i.e. 1/8th of the total), for them to be sorted by relevance, what kind of execution time would you expect on Atlas? And what would be the cost of such a configuration? Let’s say if I wanted to reduce that query time down from 10s to 1s