Elastic Search with mongodb

204 views
Skip to first unread message

Dika Andharu

unread,
Jan 29, 2015, 3:05:29 AM1/29/15
to mongod...@googlegroups.com
how to build search engine like google ?
I have problem to find array of collection in mongodb.
I want to find in mongodb but just type in short text looks like when I type db.test.find({Name: "Di"}) and the result are Name: "Dika" or Name: "Dina".
But, when I type db.test.find({Name: "Di"}) and the result is nothing appeared. So, anyone who know to built search engine like that. Please tell me...
Thanks :)

Alexander Behrens

unread,
Jan 29, 2015, 6:23:15 AM1/29/15
to mongod...@googlegroups.com
How to build a search engine like Google? Now that´s what I call an interesting question :)
I think what you are looking for is an autocomplete function that is searching on a set of documents? I would suggest using Elastic Search for searching and MongoDB for persistence. When updating MongoDB documents also update Elastic Search in the process. Elastic Search has very nice built-in tools for your purpose. Have a look at the Completion Suggester (http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-completion.html) or the N-Gram Tokenizer (http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/analysis-ngram-tokenizer.html) if hard drive space is not an issue.

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/25d195a4-a7da-4470-a461-26200d78c4da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tugdual Grall

unread,
Jan 29, 2015, 9:28:01 AM1/29/15
to mongod...@googlegroups.com
Hello

I will not directly respond to your question, since I believe that for this specific requirement you can (should?) do it with MongoDB only.

If your requirement is to be able to do autocompletion you just need to use an index in MongoDB: 

 - if you use a standard index  ensureIndex(  { name : 1 }  ); and use regular expression $regexp
   In this case you have to be careful about the case (lower/upper) and the behavior in with the index

   shell : 
       - db.test.find( { name: { $regex: /^D/ } }  )
       - db.test.find( { name: { $regex: /^d/i } }  )

  See in Java and Node:

  See documentation : http://docs.mongodb.org/manual/reference/operator/query/regex/ especially the index part:


Also you have talked about "building a search engine" and the integration with Elasticsearch is the way to go,  but you can also look at the MongoDB Full Text Search and see if this covers all your requirements:

Regards
Tug
@tgrall

Tyler Brock

unread,
Jan 29, 2015, 11:59:23 AM1/29/15
to mongod...@googlegroups.com
For the prefix case a regular expression query over a regular index works well but as of MongoDB 2.4 using a regular expression query for building a more generic search engine is not the best option. Please use text indexes/queries instead:


--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.

Stephen Steneker

unread,
Jan 29, 2015, 6:35:26 PM1/29/15
to mongod...@googlegroups.com
On Friday, 30 January 2015 03:59:23 UTC+11, Tyler Brock wrote:
For the prefix case a regular expression query over a regular index works well but as of MongoDB 2.4 using a regular expression query for building a more generic search engine is not the best option. Please use text indexes/queries instead:


Text search is useful if you want language-based stemming and word/phrase matching, but doesn't cater for fuzzy/partial matches.


Regards,
Stephen

Reply all
Reply to author
Forward
0 new messages