Views and Indexes

Have a look at Global Secondary Indexes Versus Views for a comparison of the query support options.

Also see @cihangirb’s forum post:

N1QL can only use views when an index is created using the View indexer.
CREATE INDEX … USING VIEW; is the only way to use view index with N1QL.

Stepping back, N1QL can use 2 of the indexers in the system: GSI or Views. The reason for not having any view available to N1QL is we need a specific shape in an index to optimize queries. That is why we tie down the view side but this isn’t a perpetual situation. we do plan to make views more accessible in future from N1QL. Right now, my recommendation is to use N1QL and create the best indexes for your query using N1QL and use Views for cases where you need precalculated aggregations for example interactive reports etc.

And in an older post, @geraldss wrote:

Beginning with Couchbase 4.0, N1QL will be the most general way to query Couchbase (i.e. non-KV access). Views will continue to be recommended for the following cases:

  1. Using Javascript logic as part of the query
  2. Performing aggregation (reduce), materializing the results, and then maintaing the results incrementally as the source data is modified.

(2) is important for performance, because the aggregate results are essentially pre-computed.