将具有“ IN”参数的“ where”子句的N1Ql查询转换为mapreduce视图

时间:2019-06-21 05:21:20

标签: couchbase n1ql couchbase-java-api

我有一个普通的select查询,其中已经存在mapreduce视图。

查询:

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

视图:

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

用于查询视图的键:

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

要求:现在,我们希望该视图支持在IN参数上具有status子句的查询。另外,我们想添加支持IN参数的其他参数。示例N1Ql如下所示。

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")

如何在视图上编写查询以实现此目的?我想到的唯一解决方案是在视图上触发多个查询(让我说x)

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

是否有更好的解决方案,例如批量执行此查询(使用java SDK或单个mapreduce查询?

0 个答案:

没有答案