MongoDB Text Search on Large Dataset

只谈情不闲聊 提交于 2020-05-15 07:11:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!