How to write a correct view and query for my data?

I’m a beginner.

My data is like the following.

My requirement is I can filter by expireDate, review_count and siteId.

So far, I create view like the following.

function (doc, meta)
{ emit([doc.expireDate,doc.review_count,doc.siteId], null); }

I try to use
ViewResult result = bucket.query(ViewQuery.from(designDocName, viewname).startKey(JsonArray.from(date, reviewcount, siteId)));

To search, the result will return all the data which only filter by expireDate.


If you are using Couchbase 4+, you can also use N1QL. If you are familiar with SQL, it might be easier.

My sample couchbase is 4+. but N1QL not work.

Nothing return, even the following simple query.

Cluster cluster = CouchbaseCluster.create();
Bucket bucket = cluster.openBucket(“beer-sample”);

N1qlQueryResult queryResult = bucket.query(N1qlQuery.simple(“SELECT * FROM beer-sample”));


My real couchbase is 3+. Not sure if it support N1QL.

N1QL requires 4+. You should test your query using cbq shell. If that works, then you will be able to issue the query programmatically.