Search code examples
couchbasebucket

How to execute a query in couchbase server


I want to execute this query : select path_id , usr_id from pth, so I can get all data from my bucket "path" so I can use it to generate data for my bucket "step".

I tried to create a index using this query :

CREATE INDEX idx_xref ON pth(path_id,usr_id);

And then I executed this query : select path_id , usr_id from pth

I'm expecting a json results .. but I always get this error :

[ { "code": 4000, "msg": "No index available on keyspace pth that matches your query. Use CREATE INDEX or CREATE PRIMARY INDEX to create an index, or check that your expected index is online.", "query_from_user": "select path_id , usr_id from pth;" } ]


Solution

  • select path_id, usr_id from pth where path_id IS NOT MISSING

    The leading key of the index needs to be present in the WHERE clause for index selection.

    You can find more details here: https://blog.couchbase.com/n1ql-practical-guide-second-edition/