0

I have a plain select query for which mapreduce view is already present.

Query:

select count(*) from `my-bucket` where type = 'Order' and status = 'CREATED' and timestamp > 1535605294320 and timestamp <= 1535605594320

view:

function (doc, meta) {
    if (doc._class == "com.myclass.Order"){
        emit([doc.type,doc.status, doc.timestamp], null);
    }   
}

Keys for querying the view:

Start key : ["Order","CREATED",1535605294320]  
End key : ["Order","CREATED",1535605594320]

Requirement: Now, we would want this view to support a query having IN clause on status parameter. Also, we would like to add additional parameters supporting IN parameters. Sample N1Ql would be like below.

select count(*) from `my-bucket` where type = 'Order' and orderType IN ["TYPE-A","TYPE-B","TYPE-C"]and status IN ['CREATED',""READY,"CANCELLED"] and timestamp > MILLIS("2016-05-15T03:59:00Z") and timestamp <= MILLIS("2017-05-15T03:59:00Z")

How to write a query on view to accomplish this? Only solution comes to my mind is to fire multiple (lets says x) queries on views

where x = m1*m2*....*mn   
AND m1=number of paremeters in first IN clause 
AND n=number of IN clauses.

Is there any better solution like executing this query in batch (using java SDK) or a single mapreduce query?

Manish Bansal
  • 2,400
  • 2
  • 21
  • 37
  • 1
    Is there any particular reason why you are mixing N1QL queries and views? Views are the old functionality, and will be deprecated soon. Why not try to do this in straight N1QL? – Johan Larson Jun 21 '19 at 12:06
  • @JohanLarson We are using community edition version of couchbase. As i given to understand, views are being used for performance perspective for getting counts of the number of records to be returned by the API. For actual data queries, we are using N1Ql queries itself. – Manish Bansal Jun 21 '19 at 12:09

0 Answers0