{"id":48587,"date":"2017-07-17T11:00:18","date_gmt":"2017-07-17T08:00:18","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=48587"},"modified":"2017-07-17T11:00:18","modified_gmt":"2017-07-17T08:00:18","slug":"mongodb-full-text-search-tutorial","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/","title":{"rendered":"MongoDB Full Text Search Tutorial"},"content":{"rendered":"<p>Hello, in this tutorial we are going to explore the full-text search functionalities of MongoDB right from fundamentals. MongoDB uses text indexes to perform the different full-text search operations and is case sensitive.<\/p>\n<h2>1. Introduction<\/h2>\n<p><a href=\"https:\/\/www.mongodb.com\/\" target=\"_blank\" rel=\"noopener\">MongoDB<\/a>, one of the leading NoSQL databases, is well known for its fast performance, flexible schema, scalability and great indexing capabilities. At the core of this fast performance lie the MongoDB indexes, which support efficient execution of queries by avoiding full-collection scans and hence limiting the number of documents that MongoDB searches.<\/p>\n<p>Starting from version 2.4, MongoDB began with an experimental feature supporting <strong>Full-Text Search<\/strong> using <strong>Text Indexes<\/strong>. But now, this feature has become an integral part of the product.<\/p>\n<h3>1.1 The Basics<\/h3>\n<p><em>Full-text<\/em> search refers to the technique of searching a <strong>full-text database<\/strong> against the search criteria specified by the user. It is something similar to how we search any content in any search application i.e. by entering certain string keywords\/phrases and getting back the relevant results sorted by their ranking.<\/p>\n<p>The <strong>Text Search<\/strong> uses <a href=\"https:\/\/en.wikipedia.org\/wiki\/Stemming\" target=\"_blank\" rel=\"noopener\">stemming<\/a> techniques to look for specified words in the string fields by dropping <a href=\"https:\/\/en.wikipedia.org\/wiki\/Stop_words\" target=\"_blank\" rel=\"noopener\">stop words<\/a> like <em>a<\/em>, <em>an<\/em>, <em>the<\/em>, etc.<\/p>\n<p>It has features such as:<\/p>\n<ul>\n<li>Full-text search as an index type when creating new indexes, just like any other<\/li>\n<li>Support for advanced queries, similar to the Google search syntax e.g. negation and phrase matching<\/li>\n<li>Indexing of multiple fields, with weighting to give different fields higher priority<\/li>\n<li>Supports 15 different languages<\/li>\n<\/ul>\n<h3>1.2 MongoDB Search Syntax<\/h3>\n<p>In MongoDB, <code>$text<\/code> performs a search on the content of the indexed field with a text index. In below example, we will create an index on the <strong>subject<\/strong> field of the document. A <code>$text<\/code> expression has the following syntax:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Basic Syntax<\/em><\/span><\/p>\n<pre class=\"brush:bash;wrap-lines:false;\">{\r\n  $text:\r\n    {\r\n      $search: ,\r\n      $language: ,\r\n      $caseSensitive: ,\r\n      $diacriticSensitive: \r\n    }\r\n}\r\n<\/pre>\n<p>But before we move on, let\u2019s take a look at the search fields that are supported in MongoDB.<\/p>\n<h3>1.3 MongoDB Search Fields<\/h3>\n<table>\n<tbody>\n<tr>\n<th><strong>Method<\/strong><\/th>\n<th><\/th>\n<th><strong>Description<\/strong><\/th>\n<\/tr>\n<tr>\n<td><code>$search<\/code><\/td>\n<td>Mandatory<\/td>\n<td>A string of search terms which MongoDB parses and uses to perform query the text index. MongoDB performs a logical OR search of the terms unless specified as a phrase.<\/td>\n<\/tr>\n<tr>\n<td><code>$language<\/code><\/td>\n<td>Optional<\/td>\n<td>The language that determines the list of stop words for the search and the rules for the stemmer and tokenizer. <code>$text<\/code> operator supports multiple languages, few of them are Dutch, French, German, Spanish, Arabic etc.<\/td>\n<\/tr>\n<tr>\n<td><code>$caseSensitive<\/code><\/td>\n<td>Optional<\/td>\n<td>A boolean flag to enable or disable case sensitive search. Defaults to <em>false<\/em>.<\/td>\n<\/tr>\n<tr>\n<td><code>$diacriticSensitive<\/code><\/td>\n<td>Optional<\/td>\n<td>A boolean flag to enable or disable diacritic sensitive search against version 3 text indexes.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>2. MongoDB Full-Text Search Tutorial<\/h2>\n<p>To demonstrate this example, I have inserted few records into <strong>articles<\/strong> collection, which will help you to understand the different full-text search scenarios.<\/p>\n<h3>2.1 Enabling Text Search<\/h3>\n<p>Initially, <strong>Text Search<\/strong> was an <em>experimental<\/em> feature but starting from version 2.4, this configuration is enabled by default. But if you are using the previous version of MongoDB, the following code shows how this can be done:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline\"><em>Enable Text Search Command<\/em><\/span><\/p>\n<pre class=\"brush:bash;wrap-lines:false;\">&gt; db.adminCommand({setParameter:true,textSearchEnabled:true})\r\n<\/pre>\n<h3>2.2 Creating Text Index<\/h3>\n<p>Consider the following document under the articles collection containing the id and subject fields,<\/p>\n<p><figure id=\"attachment_48589\" aria-describedby=\"caption-attachment-48589\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-48589\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-1.jpg\" alt=\"Fig. 1 MongoDB Collection\" width=\"849\" height=\"324\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-1.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-1-300x114.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-1-768x293.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-48589\" class=\"wp-caption-text\">Fig. 1 MongoDB Collection<\/figcaption><\/figure><\/p>\n<p>We will create a text index on <code>subject<\/code> field so that we can we can perform a search operation.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Creating Text Index Command<\/em><\/span><\/p>\n<pre class=\"brush:bash;wrap-lines:false;\">&gt; db.articles.ensureIndex({subject:\"text\"});\r\n<\/pre>\n<p>If the command is executed successfully, the following output will be shown:<\/p>\n<p><figure id=\"attachment_48590\" aria-describedby=\"caption-attachment-48590\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-2.jpg\"><img decoding=\"async\" class=\"size-full wp-image-48590\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-2.jpg\" alt=\"Fig. 2: Creating Text Index Command Output\" width=\"849\" height=\"80\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-2.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-2-300x28.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-2-768x72.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-48590\" class=\"wp-caption-text\">Fig. 2: Creating Text Index Command Output<\/figcaption><\/figure><\/p>\n<h3>2.3 Using Text Index<\/h3>\n<p>Now that we have created a text index on <code>subject<\/code> field, we will do the searching operation based on the different search criteria\u2019s.<\/p>\n<h4>2.3.1 $search: &#8220;coffee&#8221;<\/h4>\n<p>This query returns the documents that contain the term <code>coffee<\/code> in the indexed subject field.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Query 1<\/em><\/span><\/p>\n<pre class=\"brush:bash;wrap-lines:false;\">&gt; db.articles.find({$text: {$search: \"coffee\" }});\r\n<\/pre>\n<p>If the command is executed successfully, the following output will be shown:<\/p>\n<p><figure id=\"attachment_48591\" aria-describedby=\"caption-attachment-48591\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-3.jpg\"><img decoding=\"async\" class=\"size-full wp-image-48591\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-3.jpg\" alt=\"Fig. 3: Query 1 Output\" width=\"849\" height=\"48\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-3.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-3-300x17.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-3-768x43.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-48591\" class=\"wp-caption-text\">Fig. 3: Query 1 Output<\/figcaption><\/figure><\/p>\n<h4>2.3.2 $search: &#8220;bake coffee cake&#8221;<\/h4>\n<p>This query returns documents that contain either <code>bake<\/code> or <code>coffee<\/code> or <code>cake<\/code> in the indexed subject field, or more precisely, the stemmed version of these words (e.g. bake, baking, baked).<\/p>\n<p><span style=\"text-decoration: underline\"><em>Query 2<\/em><\/span><\/p>\n<pre class=\"brush:bash;wrap-lines:false;\">&gt; db.articles.find({ $text: {$search: \"bake coffee cake\"}});\r\n<\/pre>\n<p>If the command is executed successfully, the following output will be shown:<\/p>\n<p><figure id=\"attachment_48592\" aria-describedby=\"caption-attachment-48592\" style=\"width: 848px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-4.jpg\"><img decoding=\"async\" class=\"size-full wp-image-48592\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-4.jpg\" alt=\"Fig. 4: Query 2 Output\" width=\"848\" height=\"77\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-4.jpg 848w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-4-300x27.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-4-768x70.jpg 768w\" sizes=\"(max-width: 848px) 100vw, 848px\" \/><\/a><figcaption id=\"caption-attachment-48592\" class=\"wp-caption-text\">Fig. 4: Query 2 Output<\/figcaption><\/figure><\/p>\n<h4>2.3.3 $search: &#8220;\\&#8221;coffee shop\\&#8221;&#8221;<\/h4>\n<p>This query returns documents that contain the phrase <code>coffee shop<\/code>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Query 3<\/em><\/span><\/p>\n<pre class=\"brush:bash;wrap-lines:false;\">&gt; db.articles.find({ $text: {$search: \"\\\"coffee shop\\\"\" }});\r\n<\/pre>\n<p>If the command is executed successfully, the following output will be shown:<\/p>\n<p><figure id=\"attachment_48593\" aria-describedby=\"caption-attachment-48593\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-5.jpg\"><img decoding=\"async\" class=\"size-full wp-image-48593\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-5.jpg\" alt=\"Fig. 5: Query 3 Output\" width=\"849\" height=\"66\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-5.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-5-300x23.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-5-768x60.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-48593\" class=\"wp-caption-text\">Fig. 5: Query 3 Output<\/figcaption><\/figure><\/p>\n<h4>2.3.4 $search: &#8220;coffee -shop&#8221;<\/h4>\n<p>This query returns documents that contain the phrase <code>coffee -shop<\/code>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Query 4<\/em><\/span><\/p>\n<pre class=\"brush:bash;wrap-lines:false;\">&gt; db.articles.find({ $text: {$search: \"coffee -shop\"}});\r\n<\/pre>\n<p>If the command is executed successfully, the following output will be shown:<\/p>\n<p><figure id=\"attachment_48594\" aria-describedby=\"caption-attachment-48594\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-6.jpg\"><img decoding=\"async\" class=\"size-full wp-image-48594\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-6.jpg\" alt=\"Fig. 6: Query 4 Output\" width=\"849\" height=\"64\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-6.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-6-300x23.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-6-768x58.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-48594\" class=\"wp-caption-text\">Fig. 6: Query 4 Output<\/figcaption><\/figure><\/p>\n<h4>2.3.5 Case Sensitive Search &#8211; $search: &#8220;Coffee&#8221;<\/h4>\n<p>This query performs a case sensitive search for the term <code>Coffee<\/code>. It may impact your search performance if <code>$caseSensitive : true<\/code>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Query 5<\/em><\/span><\/p>\n<pre class=\"brush:bash;wrap-lines:false;\">&gt; db.articles.find({ $text: {$search: \"Coffee\", $caseSensitive: true}});\r\n<\/pre>\n<p>If the command is executed successfully, the following output will be shown:<\/p>\n<p><figure id=\"attachment_48595\" aria-describedby=\"caption-attachment-48595\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-7.jpg\"><img decoding=\"async\" class=\"size-full wp-image-48595\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-7.jpg\" alt=\"Fig. 7: Query 5 Output\" width=\"849\" height=\"59\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-7.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-7-300x21.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-7-768x53.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-48595\" class=\"wp-caption-text\">Fig. 7: Query 5 Output<\/figcaption><\/figure><\/p>\n<h4>2.3.6 Diacritic Sensitive Search &#8211; $search: &#8220;CAF\u00c9&#8221;<\/h4>\n<p>This query performs a diacritic sensitive text search on the term <code>CAF\u00c9<\/code>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Query 6<\/em><\/span><\/p>\n<pre class=\"brush:bash;wrap-lines:false;\">&gt; db.articles.find({$text:{ $search: \"CAF\u00c9\", $diacriticSensitive: true }});\r\n<\/pre>\n<p>If the command is executed successfully, the following output will be shown:<\/p>\n<p><figure id=\"attachment_48596\" aria-describedby=\"caption-attachment-48596\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-8.jpg\"><img decoding=\"async\" class=\"size-full wp-image-48596\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-8.jpg\" alt=\"Fig. 8: Query 6 Output\" width=\"849\" height=\"62\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-8.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-8-300x22.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-8-768x56.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-48596\" class=\"wp-caption-text\">Fig. 8: Query 6 Output<\/figcaption><\/figure><\/p>\n<h3>2.4 Deleting Text Index<\/h3>\n<p>To delete an existing text index, first find the name of the index using the below query.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Finding Index Name<\/em><\/span><\/p>\n<pre class=\"brush:bash;wrap-lines:false;\">&gt; db.articles.getIndexes();\r\n<\/pre>\n<p>If the command is executed successfully, the following output will be shown:<\/p>\n<p><figure id=\"attachment_48597\" aria-describedby=\"caption-attachment-48597\" style=\"width: 848px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-9.jpg\"><img decoding=\"async\" class=\"size-full wp-image-48597\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-9.jpg\" alt=\"Fig. 9: Index Name\" width=\"848\" height=\"282\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-9.jpg 848w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-9-300x100.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-9-768x255.jpg 768w\" sizes=\"(max-width: 848px) 100vw, 848px\" \/><\/a><figcaption id=\"caption-attachment-48597\" class=\"wp-caption-text\">Fig. 9: Index Name<\/figcaption><\/figure><\/p>\n<p>After getting the name of the index from the above query, run the below command. Here, <code>subject_text<\/code> is the name of the index.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Deleting Index<\/em><\/span><\/p>\n<pre class=\"brush:bash;wrap-lines:false;\">&gt; db.articles.dropIndex(\"subject_text\");\r\n<\/pre>\n<p>If the command is executed successfully, the following output will be shown:<\/p>\n<p><figure id=\"attachment_48598\" aria-describedby=\"caption-attachment-48598\" style=\"width: 849px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-10.jpg\"><img decoding=\"async\" class=\"size-full wp-image-48598\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-10.jpg\" alt=\"Fig. 10: Deleting Index\" width=\"849\" height=\"63\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-10.jpg 849w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-10-300x22.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/mongodb-text-search-guide-10-768x57.jpg 768w\" sizes=\"(max-width: 849px) 100vw, 849px\" \/><\/a><figcaption id=\"caption-attachment-48598\" class=\"wp-caption-text\">Fig. 10: Deleting Index<\/figcaption><\/figure><\/p>\n<h2>3. Conclusion<\/h2>\n<p>Simple, right? The new text index features provide a simple, fully consistent way to do a basic search without deploying any extra services and it highly improves the search efficiency as compared to normal search.<\/p>\n<h2>4. Download the MongoDB Files<\/h2>\n<p>This was an example of MongoDB Full-Text Search. Run the script and the result will be printed in the console window.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/07\/MongoDB-Shell-Executed-Commands-1.zip\" target=\"_blank\" rel=\"noopener\"><strong>MongoDB Shell &#8211; Executed Commands<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello, in this tutorial we are going to explore the full-text search functionalities of MongoDB right from fundamentals. MongoDB uses text indexes to perform the different full-text search operations and is case sensitive. 1. Introduction MongoDB, one of the leading NoSQL databases, is well known for its fast performance, flexible schema, scalability and great indexing &hellip;<\/p>\n","protected":false},"author":119,"featured_media":36154,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1447],"tags":[1194],"class_list":["post-48587","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mongodb","tag-mongodb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>MongoDB Full Text Search Tutorial - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this tutorial, we are going to explore and understand the full-text search functionalities of MongoDB right from the fundamentals.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MongoDB Full Text Search Tutorial - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, we are going to explore and understand the full-text search functionalities of MongoDB right from the fundamentals.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2017-07-17T08:00:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Yatin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yatin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/\"},\"author\":{\"name\":\"Yatin\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13\"},\"headline\":\"MongoDB Full Text Search Tutorial\",\"datePublished\":\"2017-07-17T08:00:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/\"},\"wordCount\":993,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg\",\"keywords\":[\"MongoDb\"],\"articleSection\":[\"MongoDB\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/\",\"name\":\"MongoDB Full Text Search Tutorial - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg\",\"datePublished\":\"2017-07-17T08:00:18+00:00\",\"description\":\"In this tutorial, we are going to explore and understand the full-text search functionalities of MongoDB right from the fundamentals.\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Software Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/software-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"MongoDB\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/software-development\/mongodb\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"MongoDB Full Text Search Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13\",\"name\":\"Yatin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg\",\"caption\":\"Yatin\"},\"description\":\"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/yatin-batra\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MongoDB Full Text Search Tutorial - Java Code Geeks","description":"In this tutorial, we are going to explore and understand the full-text search functionalities of MongoDB right from the fundamentals.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"MongoDB Full Text Search Tutorial - Java Code Geeks","og_description":"In this tutorial, we are going to explore and understand the full-text search functionalities of MongoDB right from the fundamentals.","og_url":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2017-07-17T08:00:18+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg","type":"image\/jpeg"}],"author":"Yatin","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Yatin","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/"},"author":{"name":"Yatin","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13"},"headline":"MongoDB Full Text Search Tutorial","datePublished":"2017-07-17T08:00:18+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/"},"wordCount":993,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg","keywords":["MongoDb"],"articleSection":["MongoDB"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/","url":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/","name":"MongoDB Full Text Search Tutorial - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg","datePublished":"2017-07-17T08:00:18+00:00","description":"In this tutorial, we are going to explore and understand the full-text search functionalities of MongoDB right from the fundamentals.","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/04\/mongodb-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/software-development\/mongodb\/mongodb-full-text-search-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Software Development","item":"https:\/\/examples.javacodegeeks.com\/category\/software-development\/"},{"@type":"ListItem","position":3,"name":"MongoDB","item":"https:\/\/examples.javacodegeeks.com\/category\/software-development\/mongodb\/"},{"@type":"ListItem","position":4,"name":"MongoDB Full Text Search Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13","name":"Yatin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg","caption":"Yatin"},"description":"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/examples.javacodegeeks.com\/author\/yatin-batra\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/48587","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/119"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=48587"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/48587\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/36154"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=48587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=48587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=48587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}