Can I use N1QL on Key-value store?

I stored data using upsert_multi in python. I tried to query using N1QL but getting

No primary index on keyspace test-bucket. Use CREATE PRIMARY INDEX to create one`.

Does this mean Bucket and Index are two separate things? Is it possible to query them using N1QL or any other means for further action?

The query is just SELECT * FROM `test-bucket` .

If you want to use N1QL to query you need to create an index to query, at least a primary index.
If you just want to get it back out by ID there is no need for n1ql, then you use the get method on your API.

By creating index, does it change anything to the existing bucket? Does it use more memory?

@RobGThai

You can access the data in the buckets directly (without an index) if you know the document keys.

SELECT * FROM test-bucket t
USE KEYS [“k1”, “k2”, “k3”]
WHERE t.a = 10 and t.b = “Hello”;

If you want to access the data WITHOUT knowing the keys, you do need to createa a PRIMARY INDEX to experiment with. You can optimize this by creating the index on the fields you’re filtering on…

PRIMARY INDEX: CREATE PRIMARY INDEX ON test-bucket;

Secondary indices: CREATE INDEX i1 ON test-bucket(c1, c2);

1 Like