Can N1QL queries run without GSI?

n1ql

#1

We are thinking about switching to work with N1QL, i was reading about it but didn’t find an answer to the following question:
When performing a query with N1QL without creating relevant GSIs, what will happen? I guess that GSIs are not created automatically, so will the query work? how will it get calculated without the GSI?


#2

Yes, it is possible to run N1QL queries without GSI. One option is views based indexes (the documentation has some guidance on this) and another option is the USE KEYS clause. Also, note that you don’t necessarily need a primary index. You can have just the indexes needed to satisfy your queries, which is quite flexible compared to many other databases.

See the documentation on indexing for a discussion on how this works architecturally and what the different options are.


#3

What about performing a query without any secondary indexes? If i’m not mistaking, one can query using N1QL via REST API, if i want to integrate a BI system or even just letting someone do queries by different properties, what will happen? Will the query be executed slowly or will it fail?


#4

This kind of ad-hoc query is what the primary index is used for by default. If no secondary indexes match the primary index would be used. See the documentation on primary index creation for a further description.