In order for indices to be created on the server, you must call the ensureIndices method. This method will internally generate a list of indexes which will be used and the most optimal configuration for them and build any which are missing on the server. This must be called after all models are defined, and it is a good idea to only call this when needed rather than any time your server is started.

refdoc

These indices are the most performant, but the least flexible. They allow only a single document to occupy any particular value and do direct key-value lookups using a referential document to identify a matching document in Couchbase.

In short, if you need to look up a document by a single value of a single attribute quickly (e.g. key lookups), this is the way to go. But you cannot combine multiple refdoc indexes to speed up finding
something like "all customers with first name 'John' last name 'Smith'".

view

These indices are the default and use map-reduce views. This type of index is always available once ensureIndices is called and will work with any Couchbase Server version.

Because views use map-reduce, certain types of queries can be faster as the query can be parallelized over all nodes in the cluster, with each node
returning only partial results. One of the cons of views is that they are eventually consistent by default, and incur a performance
penalty if you want consistency in the result.

n1ql

These indices utilize the new SQL-like query language available in Couchbase Server 4.0.0. These indices are more performant than views in many cases and are significantly more flexible, allowing even un-indexed searches.

N1QL indexes in Ottoman use Couchbase GSIs. If you need flexibility of query and
speed, this is the way to go.

Queries

Queries allow you to perform searches among your models. For instance allowing you to query all of the posts published by a particular user.

Finding models via N1QL Queries

All models also expose a find method that can locate model instances by any number of criteria, and that also support pagination.

This method is very useful for finding model instances under any arbitrary criteria; however keep in mind that you may wish to put
N1QL indexes on fields that would be very often a part of these queries, to improve lookup performance, and prevent Couchbase
from having to scan most or all documents in the bucket in order to find the results.

As you can see in the example below, you can even optionally specify pagination (limit/skip) and adjust the consistency of the query executed on Couchbase.