
In the above example the database name is test and collection name is articles (Because as OP has used in their Code). Most Important Note : A collection can have at most one text index. So, we can say that both scenario the creation of text index is same. To verify from the db.collection.getIndexes() method > db.articles.getIndexes()Īfter execution of text index in mongo shell, In the above statement we can see there come short note like "note" : "all indexes already exist". Let's after creation of multiple fields for the text index ( like mention in your second scenario). Now about the weight: that tells MongoDB which fields get the highest score when a search string matches. Thats what you see in the code above as many fields are annotated with TextIndexed. Should I create a index in a single command and give the equal weight: db.articles.createIndex( Although there can be one and only one full text index per collection, you can index multiple properties. So, No need to create again text index on specified both field. Here the index name "title_text_comments_text" has created for both field. You must call db.collection.getIndexes() on a collection. To make sure you have created the index on not through db.collection.getIndexes() Which returns an array that holds a list of documents that identify and describe the existing indexes on the collection. The Java driver provides the Filters.text() helper to facilitate the creation of. "createdCollectionAutomatically" : false, To perform text search, MongoDB uses a text index and the text query operator.


Should I create two separate text indexes for both of them like this: db.articles.ensureIndex( )

MONGO DB TEXT SEARCH HOW TO
I have a MongoDB collection db.articles,it has 2 keys ,"title" and "abstract".I want to do text search on these two keys.For example, the search text is "physics",and I want all the documents whose "title" or "abstract" contains keyword "physics" is returned.But how to create the text index to meet my command is really confusing me:
