Mongodb fulltext search problems

66 views
Skip to first unread message

Oleg Pavlov

unread,
Jan 16, 2017, 2:47:51 PM1/16/17
to mongodb-user
Hello!
I am using mongodb for full text search, but I've found one problem with it. I hava a database with ~300 000 documents.
When I make a query like this:
db.articles.find({ $text: { $search: {"word"} } }).pretty()
everything working well, but if I do
db.articles.find({ $text: { $search: {"\"10.5534/wjmh.2016.34.3.200\""} } }).pretty()
it works too, but very very slow (approximately 61 sec.). I add the method "explain()" and found this
 "winningPlan" : {
     
"stage" : "TEXT",
     
"indexPrefix" : {
 
 
},
 
"indexName" : "Article_TextIndex",
 
"parsedTextQuery" : {
 
"terms" : [
             
"10",
             
"200",
             
"2016",
             
"3",
             
"34",
             
"5534",
             
"wjmh"
 
],
 
"negatedTerms" : [ ],
 
"phrases" : [
         
"10.5534/wjmh.2016.34.3.200"
 
],
 
"negatedPhrases" : [ ]
 
},


It searches not only by pharses, it searches by terms too and I think this is a reason of the problem. 
Does someone know how to fix that? Or what can I do with it? Or maybe I do something wrong?

Thank you!

Wan Bachtiar

unread,
Jan 24, 2017, 8:08:46 PM1/24/17
to mongodb-user

Does someone know how to fix that? Or what can I do with it? Or maybe I do something wrong?

Hi Oleg,

The text index stores one index entry for each unique stemmed term in each indexed field for each document in the collection. Although it’s a phrase search, the index entries are tokenised and stemmed version of the field value. See more info on Text Indexes

What’s your use case ? Looking at the value it looks like a code string. Would it be possibly to store in a separate field with a different index type ?

Could you provide an example document ? Also, which MongoDB version are you using ?

Regards,

Wan.

Oleg Pavlov

unread,
Feb 28, 2017, 4:12:06 AM2/28/17
to mongodb-user
Hello, Wan. Thank you for your answer and I'm sorry it took me so long to reply. =)

Yes, the value is stored in the separated field, but I created a full text index for it, because my users would like to search by it in common way.
I think there is a solution to use separated endpoints for full text search and the value. It adds some over-engineering, but it will work.

среда, 25 января 2017 г., 4:08:46 UTC+3 пользователь Wan Bachtiar написал:
Reply all
Reply to author
Forward
0 new messages