问题
I have a book collection with currently 7.7 million records and I have setup a text index as follows that will allow me to search the collection by title
and author
as follows:
db.book.createIndex( { title: "text", author: "text" }, {sparse: true, background: true, weights: {title: 15, author: 5}, name: "text_index"} )
The problem is when I use a search query that will return a lot of results eg John
and then sort by the textScore
the time to perform the query is over 60 seconds.
Please see an example query below:
db.runCommand(
{
aggregate: "book",
pipeline : [
{ $match: { $text: { $search: "John" } } },
{ $sort: { score: { $meta: "textScore" } } },
{ $limit: 6 }
],
allowDiskUse : true
}
)
Can anyone suggest a solution to reduce this search time down to a reasonable level?
Many thanks.
来源:https://stackoverflow.com/questions/30852368/mongodb-text-search-on-large-dataset