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:
- Login to Couchbase Web Console with admin credentials
- Select Indexes >> Full Text >> New Full Text Index
- Provide name of the index: fts-user-index
- Select the bucket
- Select JSON type field as Type Identifier and provide field name: type
- Select Type Mappings >> Add Type Mapping
- Enter name as: user
- Dropdown value should be “inherit”, enabled check box is checked and only index specified field checkbox is unchecked
- Click OK to create type mapping for user
- Go to “default” type mapping and click on edit
- Uncheck enabled check box and click OK
- 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.
Wondering if you have had a chance to try the feature since it was into production last October. Thanks for the nice writeup!
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.