简体   繁体   中英

Improving MongoDB Text Search Performance

I'm looking for some advice about how improve Text Search performance with MongoDB 2.6. I am also using Mongoose.

My mongoose schema has 'body: String' which contains a large chunk of XML. I ran ensureIndex which took a few minutes...

db.models.ensureIndex({ body:"text"})

I want to search this text with a user defined string.

Model.find({ $text: { $search: searchstr }},function(err,data){ });

While there are only a few thousand documents, the search will often time out ( 2 minutes+). How can I improve my performance? Thanks!

AFAIK in general it is recomended to use the pipeline framework insted of the standard find when dealing with textSearch.

For instance doing something as:

db.model.aggregate(
   [
     { $match: { $text: { $search: "text" } } },
     { $sort: { score: { $meta: "textScore" } } },
     { $limit: 10 }
   ]
)

Will return just the first 10 elements with much the most.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM