Full Text Search Reference

Full Text Search Reference

Couchbase Server Full Text Search (FTS) enables you to create, manage, and query full text indexes on JSON documents stored in a Couchbase bucket.

Full Text Search provides powerful capabilities for querying natural language. There are three major benefits that make full text search much easier to use than alternative methods of querying, such as a wildcard match in N1QL using LIKE statements:
  • FTS provides a language-aware manner of searching, so users can type "beauties" and find results for "beauty" - which is not easy to do with regular expressions.
  • FTS provides scoring (relevance ranking) for results. Text search often returns massive numbers of matching documents, which are ordered by score so that users are presented with only a small number of results that are most likely to be the ones they are looking for. With regular expressions, there’s no practical way to simulate relevance.
  • FTS provides fast indexes that support a wide range of possible text searches. Regular expressions can be used to build one-off indexes but can’t be used to build indexes that support a full range of possible text searches.
Couchbase Server Full Text Search is powered by Bleve, a full text search and indexing library written in Go. FTS indexes your documents with Bleve and lets you use Bleve’s many powerful query types:
  • Term, Phrase, Match, Match Phrase, Prefix
  • Conjunction, Disjunction, Boolean
  • Numeric and Date Ranges
  • Query String (see Syntax)
Analyzers are a key component of search indexing (see Text Indexing). FTS includes Bleve’s general-purpose analyzers as well as pre-built text analyzers for the following languages: Arabic, English, French, German, Hindi, Italian, Persian, Portuguese, Sorani, Spanish.

FTS scores documents for relevance using Bleve’s industry standard tf-idf scoring with query time boosting.

Executing Your First Full Text Query

The Full Text Search service needs to be enabled when adding a node to a cluster during configuration. New nodes have the service enabled by default, just like data, index and N1QL query services. On Production systems we highly recommend limiting the FTS service to an independent set of nodes to help manage resources and performance.

Creating Your First Full Text Index

  1. Log in to the Couchbase Web Console, for example, http://localhost:8091/.

    Click the sidebar tabSearch, then click on the New Full Text Index button.

    A form where you can define your new index configuration is displayed.

  2. Each index needs a unique name. Type one in, such as "test-index". Only alphanumeric characters, hyphens, and underscores are allowed for index names. Also, the first character must be an alphabetic character.
  3. Choose a bucket from the drop-down list.

    There are more options, but you can ignore those for now and rely on the default values.

  4. Go! Finally, click the Create Index button.

    You should now see a summary page of your new full text index. The document count shows how many documents have been indexed so far.

Querying Your Full Text Index

  1. Click on the Search tab again.
  2. From the list, select your newly created index.
  3. In the query field, type in a query term and press the Search button.

Congratulations, you’ve just executed your first full text query!

Using the Full Text Search REST API

You can also use the full text search REST APIs to access your index. For example, if your index is named myFirstIndex, here's how you can use curl to check how many documents are indexed:
curl -u Administrator:password http://localhost:8094/api/index/myFirstIndex/count
Here's an example of using curl to query the index myFirstIndex:
curl -X POST -H "Content-Type: application/json" \
          -d '{"size":10,"query":{"query":"your search string"}}' \
That's it! You should be ready to explore, or read on to learn more about creating and querying indexes.
Note: Also, you may want to take a look at the following blog that explains how the full text search API (experimental) is expressed using the Java SDK: http://blog.couchbase.com/2016/february/cbftjavapreview