A newer version of this documentation is available.

View Latest

Indexing in Couchbase

An index is a data-structure that provides quick and efficient means to access data, that would otherwise require scanning a lot more documents. Couchbase Server provides three types of indexers which you can use to build indexes. You must keep in mind the guidelines/restrictions described in the following sections when selecting indexes in your application.

There are three types of indexers in Couchbase Server and these indexes are handled by different services.

MapReduce views

MapReduce views (also called views) are JavaScript functions defined on documents in a Couchbase bucket. Views are built incrementally, re-indexing only the documents that have changed since the last index update. Couchbase Server precomputes and stores view results before returning the results to the client. The data service is responsible to handle MapReduce views.

Spatial views

Couchbase Server uses spatial views to query geospatial information. A spatial view can contain geometric data that can be queried to return information based on whether the recorded geometries exist within a given multidimensional range. They can also be used for non-geometric multidimensional range queries.

The major difference between MapReduce views and spatial views is that instead of two functions, one each for map and reduce, spatial views contain a single function called spatial function. The spatial function is similar to the map function in MapReduce views. Spatial views also output more than a single index key per document, enabling queries against several fields in a single query. The data service is responsible to handle spatial views.

Global Secondary Index

Global Secondary Index (GSI) enables applications to perform fast query lookups and data scans at a high throughput. Unlike the view index that indexes only a subset of the data local to each data node, global secondary indexes are global across the cluster. Global secondary indexes index the entire bucket’s data in a single location and reside on the index nodes. The index service is responsible to handle GSIs.

Applications can query the Couchbase server in one of the following ways:

  • Using key-value access

  • Using the Couchbase View API. Applications can choose to use either MapReduce view indexes or spatial views.

  • Using N1QL. Applications can choose to use MapReduce views or global secondary indexes.

Passing large documents to the view engine can adversely affect the performance. Hence, Couchbase Server limits the size of the documents during indexing by default. For more information, see Server setup and usage limits.