{"id":4311,"date":"2017-12-06T07:00:56","date_gmt":"2017-12-06T15:00:56","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=4311"},"modified":"2025-06-13T20:59:27","modified_gmt":"2025-06-14T03:59:27","slug":"using-facets-couchbase-nosql-full-text-search-query","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/","title":{"rendered":"Using Facets in a Couchbase NoSQL Full Text Search Query"},"content":{"rendered":"<p>Being able to execute Full Text Search queries in <a href=\"https:\/\/www.couchbase.com\" target=\"_blank\" rel=\"noopener\">Couchbase<\/a> without the need for additional tooling such as Elastic is huge for NoSQL.<\/p>\n<p>About a year ago, I had written about using <a href=\"https:\/\/www.couchbase.com\/blog\/using-full-text-search-fts-in-couchbase-with-the-nodejs-sdk\/\" target=\"_blank\" rel=\"noopener\">Full Text Search (FTS) in Couchbase Server with the Node.js SDK<\/a>. This is back when FTS was in developer preview. While still very valid, it doesn&#8217;t encapsulate the true power of what you can do with Full Text Search. Take <a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/current\/fts\/fts-queries.html\" target=\"_blank\" rel=\"noopener\">facets<\/a> for example. Facets are aggregate information collected on a result set and are useful when it comes to categorization of result data.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-4312 size-full\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2017\/12\/amazon-facet-example.png\" alt=\"Amazon Facet Search Example\" width=\"1100\" height=\"560\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/12\/amazon-facet-example.png 1100w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/12\/amazon-facet-example-300x153.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/12\/amazon-facet-example-1024x521.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/12\/amazon-facet-example-768x391.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/12\/amazon-facet-example-20x10.png 20w\" sizes=\"auto, (max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<p>The above image shows an Amazon search. Let&#8217;s say we searched for\u00a0<strong>Pokemon<\/strong>. The categories on the left, such as,\u00a0<strong>Books<\/strong> or\u00a0<strong>Movies &amp; TV<\/strong>, can be considered search facets.<\/p>\n<p>We&#8217;re going to see how to leverage this faceted search functionality in a Node.js application.<\/p>\n<p><!--more--><\/p>\n<p>Going forward, you should already have Node.js as well as Couchbase Server 5.0+ installed and configured. We&#8217;re going to focus on the code and <a href=\"https:\/\/docs.couchbase.com\/server\/current\/n1ql\/n1ql-language-reference\/createindex.html\">index creation<\/a> to get faceted FTS working in our application.<\/p>\n<h2>Preparing a Sample Bucket with Sample Data<\/h2>\n<p>Instead of creating our own data to work with, we&#8217;re going to leverage optional sample data made available to anyone using Couchbase. We&#8217;re going to leverage the\u00a0<strong>beer-sample<\/strong> bucket.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-4313 size-full\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2017\/12\/couchbase-beer-sample-bucket.png\" alt=\"Couchbase Beer Sample Bucket\" width=\"1100\" height=\"393\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/12\/couchbase-beer-sample-bucket.png 1100w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/12\/couchbase-beer-sample-bucket-300x107.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/12\/couchbase-beer-sample-bucket-1024x366.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/12\/couchbase-beer-sample-bucket-768x274.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/12\/couchbase-beer-sample-bucket-20x7.png 20w\" sizes=\"auto, (max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<p>If you&#8217;re not sure how to install this bucket, from the Couchbase administrative dashboard, choose <strong>Settings<\/strong> and then choose\u00a0<strong>Sample Buckets<\/strong>. The sample bucket will give us around ~8,000 documents to work with.<\/p>\n<h2>Creating an Index for Full Text Search with Couchbase NoSQL<\/h2>\n<p>Before any searching can happen against the database, a special FTS index must be created. The purpose of this index is to choose two properties in any given document to search against. One property will represent what we wish to search and the other will represent our facets as well as what we wish to search against.<\/p>\n<p>Within the administrative dashboard, choose <strong>Search<\/strong> and then choose <strong>Add Index<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-4314 size-full\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2017\/12\/beer-search-fts-index.png\" alt=\"Beer Search FTS Index\" width=\"1100\" height=\"456\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/12\/beer-search-fts-index.png 1100w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/12\/beer-search-fts-index-300x124.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/12\/beer-search-fts-index-1024x424.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/12\/beer-search-fts-index-768x318.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/12\/beer-search-fts-index-20x8.png 20w\" sizes=\"auto, (max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<p>This is where things can get a little strange if this is your first time playing around with Full Text Search in Couchbase.<\/p>\n<p>When designing the index, you&#8217;ll want to give it a name. I&#8217;m using the name,\u00a0<strong>beer-search<\/strong>, but you can use whatever you want. Just make sure it is for the correct\u00a0<strong>beer-sample<\/strong> bucket. Leave the\u00a0<strong>Type Identifier<\/strong> as the default and jump into the\u00a0<strong>Type Mappings<\/strong> section.<\/p>\n<p>We plan to search against documents that have a\u00a0<strong>type<\/strong> property that matches\u00a0<strong>beer<\/strong> hence the mapping we created in the above image. It is important that we are only indexing the specified fields that follow, not the entire document. Under the new mapping, we need to create child fields. These child fields represent what we can facet and what we can search.<\/p>\n<p>The\u00a0<strong>description<\/strong> field will use the defaults, but we are selecting the\u00a0<strong>store<\/strong> option. This will allow us to access it in the result. The\u00a0<strong>category<\/strong> field will use the\u00a0<strong>keyword<\/strong> analyzer and the\u00a0<strong>store<\/strong> option. Because our categories contain multiple words per category, the analyzer needs to know how to handle the space delimited text. The\u00a0<strong>keyword<\/strong> analyzer will allow us to work with these terms.<\/p>\n<p>Finally, save the index and all documents should be indexed after a small period of time.<\/p>\n<h2>Executing a Full Text Search Query with Facets in Node.js<\/h2>\n<p>We&#8217;re going to query this newly created\u00a0<strong>beer-search<\/strong> index in two parts to mimic how it&#8217;d be done on a site like Amazon. First we&#8217;re going to execute a query based on term and show the results as well as the facets. These facets will set us up for the second part.<\/p>\n<p>Assuming you have a properly configured Node.js project available, add the following JavaScript code:<\/p>\n<pre class=\"lang:default decode:true \">const Couchbase = require(\"couchbase\");\r\n\r\nconst SearchQuery = Couchbase.SearchQuery;\r\nconst SearchFacet = Couchbase.SearchFacet;\r\n\r\nconst cluster = new Couchbase.Cluster(\"couchbase:\/\/localhost\");\r\ncluster.authenticate(\"demo\", \"123456\")\r\nconst bucket = cluster.openBucket(\"beer-sample\");\r\n\r\nvar tq1 = SearchQuery.term(\"coffee\").field(\"description\");\r\n\r\nvar query1 = SearchQuery.new(\"beer-search\", tq1);\r\nquery1.addFacet(\"categories\", SearchFacet.term(\"category\", 5));\r\nquery1.limit(3);\r\nbucket.query(query1, (error, result, meta) =&gt; {\r\n    for(var i = 0; i &lt; result.length; i++) {\r\n        console.log(\"HIT: \", result[i].id);\r\n        console.log(\"FACETS: \", meta.facets[\"categories\"].terms);\r\n    }\r\n});<\/pre>\n<p>Most of the above code is related to establishing a connection to the cluster and preparing the searching that follows. What we&#8217;re most interested in is the following:<\/p>\n<pre class=\"lang:default decode:true \">var tq1 = SearchQuery.term(\"coffee\").field(\"description\");\r\n\r\nvar query1 = SearchQuery.new(\"beer-search\", tq1);\r\nquery1.addFacet(\"categories\", SearchFacet.term(\"category\", 5));\r\nquery1.limit(3);\r\nbucket.query(query1, (error, result, meta) =&gt; {\r\n    for(var i = 0; i &lt; result.length; i++) {\r\n        console.log(\"HIT: \", result[i].id);\r\n        console.log(\"FACETS: \", meta.facets[\"categories\"].terms);\r\n    }\r\n});<\/pre>\n<p>In the above code we&#8217;re defining a search term called\u00a0<code>tq1<\/code> that searches against the <code>description<\/code> property for <code>coffee<\/code>. When we create our search query, we define the index that we had previously created and add the search term.<\/p>\n<p>We are adding a facet called <code>categories<\/code>, which is a name we just made up. The term that <code>categories<\/code> maps to is the <code>category<\/code> property within the document. We are also saying that we don&#8217;t want more than five facets to appear in our results.<\/p>\n<p>When we execute the code, we should get something that looks like the following:<\/p>\n<pre class=\"lang:default decode:true\">HIT:  lagunitas_brewing_company-cappuccino_stout\r\nFACETS:  [ { term: 'North American Ale', count: 50 },\r\n  { term: 'Irish Ale', count: 19 },\r\n  { term: 'British Ale', count: 11 },\r\n  { term: 'German Lager', count: 4 },\r\n  { term: 'Belgian and French Ale', count: 3 } ]\r\nHIT:  terrapin_beer_company-terrapin_coffee_oatmeal_imperial_stout\r\nFACETS:  [ { term: 'North American Ale', count: 50 },\r\n  { term: 'Irish Ale', count: 19 },\r\n  { term: 'British Ale', count: 11 },\r\n  { term: 'German Lager', count: 4 },\r\n  { term: 'Belgian and French Ale', count: 3 } ]\r\nHIT:  humboldt_brewing-black_xantus\r\nFACETS:  [ { term: 'North American Ale', count: 50 },\r\n  { term: 'Irish Ale', count: 19 },\r\n  { term: 'British Ale', count: 11 },\r\n  { term: 'German Lager', count: 4 },\r\n  { term: 'Belgian and French Ale', count: 3 } ]<\/pre>\n<p>Notice that the document key is printed as well as any facets that come up in the search. The facet term also includes how many times they happen. If we wanted to, we could have included other fields in the result, but the document key and facets are fine for this example.<\/p>\n<p>Now that we know our results, let&#8217;s narrow down our query.<\/p>\n<h2>Performing a Conjunctive Query with Multiple Search Terms in Node.js<\/h2>\n<p>Let&#8217;s assume that our user has searched for <code>coffee<\/code>, but has also chosen to narrow down the beer select to <code>German Lager<\/code>. This means on some front-end, the user has selected one of the facets after searching.<\/p>\n<p>Let&#8217;s take a look at the following JavaScript code:<\/p>\n<pre class=\"lang:default decode:true \">const Couchbase = require(\"couchbase\");\r\n\r\nconst SearchQuery = Couchbase.SearchQuery;\r\nconst SearchFacet = Couchbase.SearchFacet;\r\n\r\nconst cluster = new Couchbase.Cluster(\"couchbase:\/\/localhost\");\r\ncluster.authenticate(\"demo\", \"123456\")\r\nconst bucket = cluster.openBucket(\"beer-sample\");\r\n\r\nvar tq1 = SearchQuery.term(\"coffee\").field(\"description\");\r\nvar tq2 = SearchQuery.term(\"German Lager\").field(\"category\");\r\nvar conjunction = SearchQuery.conjuncts(tq1, tq2);\r\n\r\nquery2 = SearchQuery.new(\"beer-search\", conjunction);\r\nquery2.addFacet(\"categories\", SearchFacet.term(\"category\", 5));\r\nquery2.limit(3);\r\nbucket.query(query2, (error, result, meta) =&gt; {\r\n    for(var i = 0; i &lt; result.length; i++) {\r\n        console.log(\"HIT: \", result[i].id);\r\n        console.log(\"FACETS: \", meta.facets[\"categories\"].terms);\r\n    }\r\n});<\/pre>\n<p>We&#8217;ve made some changes.<\/p>\n<p>Instead of having a single search term, we now have two search terms. One will search against the <code>description<\/code>, like the previous, but the new term will search against the <code>category<\/code> property. To search using two terms we have to perform what&#8217;s called a conjunctive query.<\/p>\n<p>Executing the above code would yield a result that looks like the following:<\/p>\n<pre class=\"lang:default decode:true \">HIT:  sprecher_brewing-black_bavarian_lager\r\nFACETS:  [ { term: 'German Lager', count: 4 } ]\r\nHIT:  red_oak_brewery-battlefield_bock\r\nFACETS:  [ { term: 'German Lager', count: 4 } ]\r\nHIT:  four_peaks_brewing-black_betty_schwartzbier\r\nFACETS:  [ { term: 'German Lager', count: 4 } ]<\/pre>\n<p>Notice that our results only contain German Lagers in comparison to the variety we saw previously. This is because we were able to use the facet information to narrow down our results with a secondary query.<\/p>\n<h2>The Full JavaScript Code of the Example<\/h2>\n<p>To see everything put together, it would look like the following:<\/p>\n<pre class=\"lang:default decode:true \">const Couchbase = require(\"couchbase\");\r\n\r\nconst SearchQuery = Couchbase.SearchQuery;\r\nconst SearchFacet = Couchbase.SearchFacet;\r\n\r\nconst cluster = new Couchbase.Cluster(\"couchbase:\/\/localhost\");\r\ncluster.authenticate(\"demo\", \"123456\")\r\nconst bucket = cluster.openBucket(\"beer-sample\");\r\n\r\nvar tq1 = SearchQuery.term(\"coffee\").field(\"description\");\r\n\r\nvar query1 = SearchQuery.new(\"beer-search\", tq1);\r\nquery1.addFacet(\"categories\", SearchFacet.term(\"category\", 5));\r\nquery1.limit(3);\r\nbucket.query(query1, (error, result, meta) =&gt; {\r\n    for(var i = 0; i &lt; result.length; i++) {\r\n        console.log(\"HIT: \", result[i].id);\r\n        console.log(\"FACETS: \", meta.facets[\"categories\"].terms);\r\n    }\r\n});\r\n\r\nvar tq2 = SearchQuery.term(\"German Lager\").field(\"category\");\r\nvar conjunction = SearchQuery.conjuncts(tq1, tq2);\r\n\r\nquery2 = SearchQuery.new(\"beer-search\", conjunction);\r\nquery2.addFacet(\"categories\", SearchFacet.term(\"category\", 5));\r\nquery2.limit(3);\r\nbucket.query(query2, (error, result, meta) =&gt; {\r\n    for(var i = 0; i &lt; result.length; i++) {\r\n        console.log(\"HIT: \", result[i].id);\r\n        console.log(\"FACETS: \", meta.facets[\"categories\"].terms);\r\n    }\r\n});<\/pre>\n<p>Take note that the above code is not realistic. For one it is asynchronous. The reality of things would be controlled by user interaction. User performs one search, alters something, then performs a secondary search like previously described.<\/p>\n<h2>Conclusion<\/h2>\n<p>You just saw how to search with facets in <a href=\"https:\/\/www.couchbase.com\" target=\"_blank\" rel=\"noopener\">Couchbase<\/a> using Full Text Search (FTS) and the Node.js SDK. FTS is a way to query natural language and is very different than N1QL. FTS is very powerful and a lot of great things can be done.<\/p>\n<p>For more information on using Full Text Search with Couchbase, check out the <a href=\"https:\/\/developer.couchbase.com\" target=\"_blank\" rel=\"noopener\">Couchbase Developer Portal<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Being able to execute Full Text Search queries in Couchbase without the need for additional tooling such as Elastic is huge for NoSQL. About a year ago, I had written about using Full Text Search (FTS) in Couchbase Server with [&hellip;]<\/p>\n","protected":false},"author":63,"featured_media":13873,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1816,2165,9327,1822],"tags":[1543],"ppma_author":[9032],"class_list":["post-4311","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-couchbase-server","category-full-text-search","category-javascript","category-node-js","tag-javascript"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.7.1 (Yoast SEO v25.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using Facets in a Couchbase NoSQL Full Text Search Query<\/title>\n<meta name=\"description\" content=\"Learn how to use facets for result aggregation in a Full Text Search (FTS) query made with Node.js and the NoSQL database, Couchbase Server.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using Facets in a Couchbase NoSQL Full Text Search Query\" \/>\n<meta property=\"og:description\" content=\"Learn how to use facets for result aggregation in a Full Text Search (FTS) query made with Node.js and the NoSQL database, Couchbase Server.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/thepolyglotdeveloper\" \/>\n<meta property=\"article:published_time\" content=\"2017-12-06T15:00:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T03:59:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/12\/amazon-facet-example.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"560\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Nic Raboy, Developer Advocate, Couchbase\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@nraboy\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nic Raboy, Developer Advocate, Couchbase\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/\"},\"author\":{\"name\":\"Nic Raboy, Developer Advocate, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/bb545ebe83bb2d12f91095811d0a72e1\"},\"headline\":\"Using Facets in a Couchbase NoSQL Full Text Search Query\",\"datePublished\":\"2017-12-06T15:00:56+00:00\",\"dateModified\":\"2025-06-14T03:59:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/\"},\"wordCount\":1101,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"keywords\":[\"javascript\"],\"articleSection\":[\"Couchbase Server\",\"Full-Text Search\",\"JavaScript\",\"Node.js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/\",\"name\":\"Using Facets in a Couchbase NoSQL Full Text Search Query\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2017-12-06T15:00:56+00:00\",\"dateModified\":\"2025-06-14T03:59:27+00:00\",\"description\":\"Learn how to use facets for result aggregation in a Full Text Search (FTS) query made with Node.js and the NoSQL database, Couchbase Server.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"width\":1800,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using Facets in a Couchbase NoSQL Full Text Search Query\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/bb545ebe83bb2d12f91095811d0a72e1\",\"name\":\"Nic Raboy, Developer Advocate, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/8863514d8bed0cf6080f23db40e00354\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g\",\"caption\":\"Nic Raboy, Developer Advocate, Couchbase\"},\"description\":\"Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in Java, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Apache Cordova. Nic writes about his development experiences related to making web and mobile development easier to understand.\",\"sameAs\":[\"https:\/\/www.thepolyglotdeveloper.com\",\"https:\/\/www.facebook.com\/thepolyglotdeveloper\",\"https:\/\/x.com\/nraboy\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/nic-raboy-2\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Using Facets in a Couchbase NoSQL Full Text Search Query","description":"Learn how to use facets for result aggregation in a Full Text Search (FTS) query made with Node.js and the NoSQL database, Couchbase Server.","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:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/","og_locale":"en_US","og_type":"article","og_title":"Using Facets in a Couchbase NoSQL Full Text Search Query","og_description":"Learn how to use facets for result aggregation in a Full Text Search (FTS) query made with Node.js and the NoSQL database, Couchbase Server.","og_url":"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/","og_site_name":"The Couchbase Blog","article_author":"https:\/\/www.facebook.com\/thepolyglotdeveloper","article_published_time":"2017-12-06T15:00:56+00:00","article_modified_time":"2025-06-14T03:59:27+00:00","og_image":[{"width":1100,"height":560,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2017\/12\/amazon-facet-example.png","type":"image\/png"}],"author":"Nic Raboy, Developer Advocate, Couchbase","twitter_card":"summary_large_image","twitter_creator":"@nraboy","twitter_misc":{"Written by":"Nic Raboy, Developer Advocate, Couchbase","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/"},"author":{"name":"Nic Raboy, Developer Advocate, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/bb545ebe83bb2d12f91095811d0a72e1"},"headline":"Using Facets in a Couchbase NoSQL Full Text Search Query","datePublished":"2017-12-06T15:00:56+00:00","dateModified":"2025-06-14T03:59:27+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/"},"wordCount":1101,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","keywords":["javascript"],"articleSection":["Couchbase Server","Full-Text Search","JavaScript","Node.js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/","url":"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/","name":"Using Facets in a Couchbase NoSQL Full Text Search Query","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2017-12-06T15:00:56+00:00","dateModified":"2025-06-14T03:59:27+00:00","description":"Learn how to use facets for result aggregation in a Full Text Search (FTS) query made with Node.js and the NoSQL database, Couchbase Server.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","width":1800,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/using-facets-couchbase-nosql-full-text-search-query\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Using Facets in a Couchbase NoSQL Full Text Search Query"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/bb545ebe83bb2d12f91095811d0a72e1","name":"Nic Raboy, Developer Advocate, Couchbase","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/8863514d8bed0cf6080f23db40e00354","url":"https:\/\/secure.gravatar.com\/avatar\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g","caption":"Nic Raboy, Developer Advocate, Couchbase"},"description":"Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in Java, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Apache Cordova. Nic writes about his development experiences related to making web and mobile development easier to understand.","sameAs":["https:\/\/www.thepolyglotdeveloper.com","https:\/\/www.facebook.com\/thepolyglotdeveloper","https:\/\/x.com\/nraboy"],"url":"https:\/\/www.couchbase.com\/blog\/author\/nic-raboy-2\/"}]}},"authors":[{"term_id":9032,"user_id":63,"is_guest":0,"slug":"nic-raboy-2","display_name":"Nic Raboy, Developer Advocate, Couchbase","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/bedeb68368d4681aca4c74fe5f697f0c423b80d498ec50fd915ba018b72c101f?s=96&d=mm&r=g","author_category":"","last_name":"Raboy","first_name":"Nic","job_title":"","user_url":"https:\/\/www.thepolyglotdeveloper.com","description":"Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in Java, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Apache Cordova. Nic writes about his development experiences related to making web and mobile development easier to understand."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/4311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=4311"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/4311\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/13873"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=4311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=4311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=4311"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=4311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}