Farah
Farah

Reputation: 45

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;" } ]

Upvotes: 2

Views: 301

Answers (2)

Farah
Farah

Reputation: 45

I solved the problem by creating a primary index : CREATE PRIMARY INDEX ON pth Thank you all for your help :))

Upvotes: 0

deepkaran
deepkaran

Reputation: 71

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/

Upvotes: 1

Related Questions