Couchbase – Full Text Search (FTS)

Couchbase Server (A.K.A. Couchbase) is open source, NoSQL, document oriented database that stores JSON documents. Couchbase has recently introduced a new feature – Full Text Search (FTS). This feature is currently a Developer Preview Version (as of Aug 24, 2017). Couchbase has provided decent documentation for FTS which can be access here.

Couchbase stores all the JSON documents in a Bucket. Using N1QL, you can query these documents. These queries are more like SQL statements but for JSON. On the other hand, with FTS you can use following powerful query types:

  • Term, Phrase, Match, Match Phrase, Prefix
  • Conjunction, Disjunction, Boolean
  • Numeric and Date Ranges
  • Query String

To use FTS feature, one must have at least one node with FTS service enabled. Here is the link which describes commands to add or join node with a cluster by enabling various services: https://developer.couchbase.com/documentation/server/current/rest-api/rest-node-services.html

In order to use FTS feature, we need to make our bucket searchable by defining search index. This can be done using Couchbase Console or by executing CURL command. For example, we will be creating multiple indexes based on a JSON field: type. You can use any field from your JSON document. If this field is present in each JSON document, then that is even better.

To create search index for “user”, we will perform following steps:

  1. Login to Couchbase Web Console with admin credentials
  2. Select Indexes >> Full Text >> New Full Text Index
  3. Provide name of the index: fts-user-index
  4. Select the bucket
  5. Select JSON type field as Type Identifier and provide field name: type
  6. Select Type Mappings >> Add Type Mapping
  7. Enter name as: user
  8. Dropdown value should be “inherit”, enabled check box is checked and only index specified field checkbox is unchecked
  9. Click OK to create type mapping for user
  10. Go to “default” type mapping and click on edit
  11. Uncheck enabled check box and click OK
  12. Click on “Create Index” button

Couchbase has plans to integrate this feature with N1QL in future, but for now it can be accessed from Couchbase Admin Console or using Couchbase SDK or library. I have written following Java class with various operations.

Since Couchbase FTS feature is currently (as of Aug 24, 2017) “experimental”, the functionality can change in future.

2 thoughts on “Couchbase – Full Text Search (FTS)

  1. Tyler Mitchell Reply

    Wondering if you have had a chance to try the feature since it was into production last October. Thanks for the nice writeup!

    • Sagar Chaudhari Post authorReply

      Thanks Tyler. We did a POC when it was in experimental phase. We haven’t implemented this feature yet, but we do have plans to implement it by the end of this year or early next year.

Leave a Reply

Your email address will not be published. Required fields are marked *