The Index Service supports the creation of primary and secondary indexes on items stored within Couchbase clusters. Indexes enable and enhance the performance of query operations.
The Index Service is used to create indexes from predefined subsets of bucket-data. The Query Service relies on indexes provided by the Index Service.
The N1QL query language is used to instruct the Index Service to create indexes. The Index Service can create two types of indexes:
Secondary: Based on an attribute within a document. The value associated with the attribute can be of any type: scalar, object, or array.
A Secondary Index is frequently referred to as a Global Secondary Index, or GSI. This is the kind of index used most frequently in Couchbase Server, for queries performed with the N1Ql query-language. The CREATE INDEX statement is used to create secondary indexes.
Primary: Based on on the unique key of every item in a specified bucket. Every primary index is maintained asynchronously.
A primary index is intended to be used for simple queries, which have no filters or predicates. The CREATE PRIMARY INDEX statement is used to create primary indexes.
Couchbase Cloud supports standard index storage for saving indexes. By default, an index is saved on the node on which it is created. Each index is created on one bucket only; but multiple indexes may be created on a single bucket.
Like the other Couchbase services, the Index Service can be deployed during cluster creation, or by adding it to an existing cluster. The Index Service depends on the Data Service for underlying functionality, and depends on the Query Service for creating and managing indexes via the N1QL query language. These services must also be deployed on the cluster in order to use the Index Service. (Information about how these services interact with one another can be found in the Couchbase Server documentation.)