I have just started to work on indexing parts of couchbase and I’m little bit confused especially distinction between indexing & views. For example, I created a view by map-reduce function so that I had an index with some filtered data. On the other hand, I decided to use CREATE INDEX command with some filter expressions and by using VIEW indexer.
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.
@zero Would be great if you can share your usecase - what is the business logic that you are trying to get done? this will help in suggesting if Views or N1QL+GSI will help your cause. Generally, I would lean towards the latter(N1QL+GSI) as it is an easier data access pattern(declarative), and will try to solve most of your usecases.